From 4a1cfe0c91529d24fe93f1129c56f331ad079bcb Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Mon, 27 Mar 2023 11:07:11 +0200 Subject: [PATCH] Fix using only username in URI handlers. --- CHANGELOG.md | 5 +++++ linphone-app/src/app/cli/Cli.cpp | 16 ++++++++++++---- linphone-app/src/utils/Utils.cpp | 6 ++++++ linphone-app/src/utils/Utils.hpp | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78fa616d0..af6032879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - File viewer in chats (Image/Animated Image/Video/Texts) with the option to export the file. - Accept/decline CLI commands. +## 5.0.15 - undefined + +## Fixed +- Fix using only username in URI handlers. + ## 5.0.14 - 2023-03-16 ## Fixed diff --git a/linphone-app/src/app/cli/Cli.cpp b/linphone-app/src/app/cli/Cli.cpp index e420d9d08..9b312ce53 100644 --- a/linphone-app/src/app/cli/Cli.cpp +++ b/linphone-app/src/app/cli/Cli.cpp @@ -336,6 +336,8 @@ void Cli::Command::execute (QHash &args) const { void Cli::Command::executeUri (const shared_ptr &address) const { QHash args; QString qAddress = Utils::coreStringToAppString(address->asString()); + if(address->getDomain() == "" && qAddress.back() == '@') + qAddress.remove(qAddress.size()-1, 1); QUrl url(qAddress); QString query = url.query(); @@ -355,7 +357,7 @@ void Cli::Command::executeUri (const shared_ptr &address) con const string header = address->getHeader(Utils::appStringToCoreString(argName)); args[argName] = QByteArray::fromBase64(QByteArray(header.c_str(), int(header.length()))); } - args["sip-address"] = Utils::coreStringToAppString(address->asString()); + args["sip-address"] = qAddress; execute(args); } @@ -501,15 +503,21 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) { *format = CliFormat; mCommands["show"].execute(args); }else{ - shared_ptr address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(transformedCommand));// Test if command is an address + shared_ptr address; + if(Utils::isUsername(transformedCommand)){ + address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(transformedCommand+"@to.remove")); + if(address) + address->setDomain(""); + }else + address = linphone::Factory::get()->createAddress(Utils::appStringToCoreString(transformedCommand));// Test if command is an address if (format) *format = UriFormat; qInfo() << QStringLiteral("Detecting URI command: `%1`...").arg(command); QString functionName; if( address) { functionName = Utils::coreStringToAppString(address->getHeader("method")).isEmpty() - ? QStringLiteral("call") - : Utils::coreStringToAppString(address->getHeader("method")); + ? QStringLiteral("call") + : Utils::coreStringToAppString(address->getHeader("method")); }else{ QStringList fields = command.split('?'); if(fields.size() >1){ diff --git a/linphone-app/src/utils/Utils.cpp b/linphone-app/src/utils/Utils.cpp index 8f768aa47..59be4e804 100644 --- a/linphone-app/src/utils/Utils.cpp +++ b/linphone-app/src/utils/Utils.cpp @@ -623,6 +623,12 @@ bool Utils::isPhoneNumber(const QString& txt){ return account && account->isPhoneNumber(Utils::appStringToCoreString(txt)); } +bool Utils::isUsername(const QString& txt){ + QRegularExpression regex("^(?$"); + QRegularExpressionMatch match = regex.match(txt); + return match.hasMatch(); // true +} + QSize Utils::getImageSize(const QString& url){ QString path; QUrl urlDecode(url); diff --git a/linphone-app/src/utils/Utils.hpp b/linphone-app/src/utils/Utils.hpp index 75c4862df..d2d454590 100644 --- a/linphone-app/src/utils/Utils.hpp +++ b/linphone-app/src/utils/Utils.hpp @@ -64,6 +64,7 @@ public: Q_INVOKABLE static bool isMe(const QString& address); Q_INVOKABLE static bool isAnimatedImage(const QString& path); Q_INVOKABLE static bool isPhoneNumber(const QString& txt); + Q_INVOKABLE static bool isUsername(const QString& txt); // Check with Regex Q_INVOKABLE QSize getImageSize(const QString& url); Q_INVOKABLE static QPoint getCursorPosition(); Q_INVOKABLE static QString getFileChecksum(const QString& filePath);