From 0acb7b67368b0d8ea355f1adbfb9ded25bb894ca Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Mon, 25 Nov 2024 06:35:36 +0100 Subject: [PATCH] Align account parameter setting with Android + sdk crash workaround --- Linphone/model/account/AccountModel.cpp | 28 ++++++++++++------- Linphone/tool/Utils.cpp | 27 ------------------ Linphone/tool/Utils.hpp | 3 -- .../AccountSettingsParametersLayout.qml | 18 ++---------- 4 files changed, 21 insertions(+), 55 deletions(-) diff --git a/Linphone/model/account/AccountModel.cpp b/Linphone/model/account/AccountModel.cpp index 786e566f5..fd388c059 100644 --- a/Linphone/model/account/AccountModel.cpp +++ b/Linphone/model/account/AccountModel.cpp @@ -189,8 +189,10 @@ void AccountModel::setNotificationsAllowed(bool value) { void AccountModel::setMwiServerAddress(QString value) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); auto params = mMonitor->getParams()->clone(); - auto address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(value)); - if (address) { + auto address = value.isEmpty() + ? nullptr + : CoreModel::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(value), false); + if (value.isEmpty() || address) { params->setMwiServerAddress(address); mMonitor->setParams(params); emit mwiServerAddressChanged(value); @@ -208,7 +210,7 @@ void AccountModel::setTransport(linphone::TransportType value) { void AccountModel::setServerAddress(QString value) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); auto params = mMonitor->getParams()->clone(); - auto address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(value)); + auto address = CoreModel::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(value), false); if (address) { params->setServerAddress(address); mMonitor->setParams(params); @@ -230,6 +232,7 @@ void AccountModel::setStunServer(QString value) { auto policy = params->getNatPolicy(); if (!policy) policy = mMonitor->getCore()->createNatPolicy(); policy->setStunServer(Utils::appStringToCoreString(value)); + policy->enableStun(!value.isEmpty()); params->setNatPolicy(policy); mMonitor->setParams(params); emit stunServerChanged(value); @@ -273,8 +276,10 @@ void AccountModel::setExpire(int value) { void AccountModel::setConferenceFactoryAddress(QString value) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); auto params = mMonitor->getParams()->clone(); - auto address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(value)); - if (address) { + auto address = value.isEmpty() + ? nullptr + : CoreModel::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(value), false); + if (value.isEmpty() || address) { params->setConferenceFactoryAddress(address); mMonitor->setParams(params); emit conferenceFactoryAddressChanged(value); @@ -284,8 +289,10 @@ void AccountModel::setConferenceFactoryAddress(QString value) { void AccountModel::setAudioVideoConferenceFactoryAddress(QString value) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); auto params = mMonitor->getParams()->clone(); - auto address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(value)); - if (address) { + auto address = value.isEmpty() + ? nullptr + : CoreModel::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(value), false); + if (value.isEmpty() || address) { params->setAudioVideoConferenceFactoryAddress(address); mMonitor->setParams(params); emit audioVideoConferenceFactoryAddressChanged(value); @@ -296,7 +303,6 @@ void AccountModel::setAudioVideoConferenceFactoryAddress(QString value) { void AccountModel::setLimeServerUrl(QString value) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); auto params = mMonitor->getParams()->clone(); - auto address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(value)); params->setLimeServerUrl(Utils::appStringToCoreString(value)); mMonitor->setParams(params); emit limeServerUrlChanged(value); @@ -323,8 +329,10 @@ bool AccountModel::getShowMwi() { void AccountModel::setVoicemailAddress(QString value) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); auto params = mMonitor->getParams()->clone(); - auto address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(value)); - if (address) { + auto address = value.isEmpty() + ? nullptr + : CoreModel::getInstance()->getCore()->interpretUrl(Utils::appStringToCoreString(value), false); + if (value.isEmpty() || address) { params->setVoicemailAddress(address); mMonitor->setParams(params); emit voicemailAddressChanged(value); diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 845e76455..d94804e83 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -339,33 +339,6 @@ VariantObject *Utils::interpretUrl(QString uri) { return data; } -VariantObject *Utils::isValidSIPAddress(QString uri) { - VariantObject *data = new VariantObject(QVariant(false)); - if (!data) return nullptr; - data->makeRequest([uri]() -> QVariant { - return QVariant(linphone::Factory::get()->createAddress(Utils::appStringToCoreString(uri)) != nullptr); - }); - data->requestValue(); - return data; -} - -bool Utils::isValidIPAddress(const QString &host) { - QHostAddress address; - return address.setAddress(host); -} - -bool Utils::isValidHostname(const QString &hostname) { - QRegularExpression regex("^[a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?$"); - QStringList labels = hostname.split('.'); - if (labels.size() > 127) // More than 127 labels is invalid - return false; - foreach (const QString &label, labels) { - if (!regex.match(label).hasMatch() || label.length() > 63) // Label length must be between 1 and 63 - return false; - } - return hostname.length() <= 253; // Total length should be <= 253 -} - bool Utils::isValidURL(const QString &url) { return QUrl(url).isValid(); } diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index ba8f3bd0a..726495198 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -117,9 +117,6 @@ public: Q_INVOKABLE static int timeOffset(QDateTime start, QDateTime end); Q_INVOKABLE static int daysOffset(QDateTime start, QDateTime end); Q_INVOKABLE static VariantObject *interpretUrl(QString uri); - Q_INVOKABLE static VariantObject *isValidSIPAddress(QString uri); - Q_INVOKABLE static bool isValidIPAddress(const QString &host); - Q_INVOKABLE static bool isValidHostname(const QString &hostname); Q_INVOKABLE static bool isValidURL(const QString &url); Q_INVOKABLE static VariantObject *findAvatarByAddress(const QString &address); Q_INVOKABLE static VariantObject *findFriendByAddress(const QString &address); diff --git a/Linphone/view/Page/Layout/Settings/AccountSettingsParametersLayout.qml b/Linphone/view/Page/Layout/Settings/AccountSettingsParametersLayout.qml index 215766628..6cb1df2c8 100644 --- a/Linphone/view/Page/Layout/Settings/AccountSettingsParametersLayout.qml +++ b/Linphone/view/Page/Layout/Settings/AccountSettingsParametersLayout.qml @@ -36,16 +36,14 @@ AbstractSettingsLayout { propertyName: "mwiServerAddress" propertyOwner: account.core title: qsTr("URI du serveur de messagerie vocale") - isValid: function(text) { return UtilsCpp.isValidSIPAddress(text); } - toValidate: true Layout.fillWidth: true + isValid: function(text) { return text.length == 0 || !text.endsWith(".") } // work around sdk crash when adress ends with . + toValidate: true } DecoratedTextField { propertyName: "voicemailAddress" propertyOwner: account.core title: qsTr("URI de messagerie vocale") - isValid: function(text) { return UtilsCpp.isValidSIPAddress(text); } - toValidate: true Layout.fillWidth: true } } @@ -76,8 +74,6 @@ AbstractSettingsLayout { title: qsTr("URL du serveur mandataire") propertyName: "serverAddress" propertyOwner: account.core - isValid: function(text) { return UtilsCpp.isValidSIPAddress(text); } - toValidate: true } SwitchSetting { titleText: qsTr("Serveur mandataire sortant") @@ -89,8 +85,6 @@ AbstractSettingsLayout { propertyName: "stunServer" propertyOwner: account.core title: qsTr("Adresse du serveur STUN") - isValid: function(text) { return UtilsCpp.isValidIPAddress(text) || UtilsCpp.isValidHostname(text); } - toValidate: true } SwitchSetting { titleText: qsTr("Activer ICE") @@ -113,7 +107,7 @@ AbstractSettingsLayout { propertyOwner: account.core title: qsTr("Expiration (en seconde)") canBeEmpty: false - isValid: function(text) { return !isNaN(Number(text)); } + isValid: function(text) { return !isNaN(Number(text)) } toValidate: true } DecoratedTextField { @@ -121,25 +115,19 @@ AbstractSettingsLayout { title: qsTr("URI de l’usine à conversations") propertyName: "conferenceFactoryAddress" propertyOwner: account.core - isValid: function(text) { return UtilsCpp.isValidSIPAddress(text); } - toValidate: true } DecoratedTextField { Layout.fillWidth: true title: qsTr("URI de l’usine à réunions") propertyName: "audioVideoConferenceFactoryAddress" propertyOwner: account.core - isValid: function(text) { return UtilsCpp.isValidSIPAddress(text); } visible: !SettingsCpp.disableMeetingsFeature - toValidate: true } DecoratedTextField { Layout.fillWidth: true title: qsTr("URL du serveur d’échange de clés de chiffrement") propertyName: "limeServerUrl" propertyOwner: account.core - isValid: function(text) { return UtilsCpp.isValidURL(text); } - toValidate: true } } }