mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-17 11:28:07 +00:00
try to fix read access violation (Mantis 0013842)
This commit is contained in:
parent
6b02ebed39
commit
e08d5e0377
2 changed files with 26 additions and 20 deletions
|
|
@ -83,14 +83,19 @@ void MagicSearchModel::onSearchResultsReceived(const std::shared_ptr<linphone::M
|
|||
auto ldapFriends = ToolModel::getLdapFriendList();
|
||||
emit searchResultsReceived(results);
|
||||
for (auto result : results) {
|
||||
if (!result) continue;
|
||||
auto f = result->getFriend();
|
||||
auto friendsManager = FriendsManager::getInstance();
|
||||
if (f) {
|
||||
qDebug() << "friend exists, append to unknown map";
|
||||
auto friendAddress = f->getAddress();
|
||||
friendsManager->appendUnknownFriend(friendAddress->clone(), f);
|
||||
if (friendsManager->isInOtherAddresses(Utils::coreStringToAppString(friendAddress->asStringUriOnly()))) {
|
||||
friendsManager->removeOtherAddress(Utils::coreStringToAppString(friendAddress->asStringUriOnly()));
|
||||
auto friendAddress = f->getAddress() ? f->getAddress()->clone() : nullptr;
|
||||
if (friendAddress) {
|
||||
friendAddress->clean();
|
||||
friendsManager->appendUnknownFriend(friendAddress, f);
|
||||
if (friendsManager->isInOtherAddresses(
|
||||
Utils::coreStringToAppString(friendAddress->asStringUriOnly()))) {
|
||||
friendsManager->removeOtherAddress(Utils::coreStringToAppString(friendAddress->asStringUriOnly()));
|
||||
}
|
||||
}
|
||||
}
|
||||
auto fList = f ? f->getFriendList() : nullptr;
|
||||
|
|
@ -127,7 +132,7 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptr<linphone
|
|||
if (ToolModel::friendIsInFriendList(friendList, linphoneFriend))
|
||||
return; // Already exist. We don't need to manipulate list.
|
||||
for (auto address : linphoneFriend->getAddresses()) {
|
||||
auto existingFriend = friendList->findFriendByAddress(address);
|
||||
auto existingFriend = friendList ? friendList->findFriendByAddress(address) : nullptr;
|
||||
if (existingFriend) {
|
||||
friendList->removeFriend(existingFriend);
|
||||
friendList->addFriend(linphoneFriend);
|
||||
|
|
@ -135,7 +140,7 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptr<linphone
|
|||
}
|
||||
}
|
||||
for (auto number : linphoneFriend->getPhoneNumbers()) {
|
||||
auto existingFriend = friendList->findFriendByPhoneNumber(number);
|
||||
auto existingFriend = friendList ? friendList->findFriendByPhoneNumber(number) : nullptr;
|
||||
if (existingFriend) {
|
||||
friendList->removeFriend(existingFriend);
|
||||
friendList->addFriend(linphoneFriend);
|
||||
|
|
@ -143,6 +148,6 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptr<linphone
|
|||
}
|
||||
}
|
||||
qInfo() << log().arg("Adding Friend:") << linphoneFriend.get();
|
||||
friendList->addFriend(linphoneFriend);
|
||||
if (friendList) friendList->addFriend(linphoneFriend);
|
||||
emit CoreModel::getInstance()->friendCreated(linphoneFriend);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "ToolModel.hpp"
|
||||
#include "core/App.hpp"
|
||||
#include "core/conference/ConferenceInfoCore.hpp"
|
||||
#include "core/path/Paths.hpp"
|
||||
#include "model/core/CoreModel.hpp"
|
||||
#include "model/friend/FriendsManager.hpp"
|
||||
|
|
@ -120,20 +121,18 @@ std::shared_ptr<linphone::Friend> ToolModel::findFriendByAddress(const QString &
|
|||
auto defaultFriendList = CoreModel::getInstance()->getCore()->getDefaultFriendList();
|
||||
if (!defaultFriendList) return nullptr;
|
||||
auto linphoneAddr = ToolModel::interpretUrl(address);
|
||||
if (linphoneAddr)
|
||||
return ToolModel::findFriendByAddress(linphoneAddr);
|
||||
else
|
||||
return nullptr;
|
||||
if (linphoneAddr) return ToolModel::findFriendByAddress(linphoneAddr);
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<linphone::Friend> ToolModel::findFriendByAddress(std::shared_ptr<linphone::Address> linphoneAddr) {
|
||||
auto friendsManager = FriendsManager::getInstance();
|
||||
QString key = Utils::coreStringToAppString(linphoneAddr->asStringUriOnly());
|
||||
if (friendsManager->isInKnownFriends(key)) {
|
||||
// qDebug() << key << "have been found in known friend, return it";
|
||||
// qDebug() << key << "have been found in known friend, return it";
|
||||
return friendsManager->getKnownFriendAtKey(key);
|
||||
} else if (friendsManager->isInUnknownFriends(key)) {
|
||||
// qDebug() << key << "have been found in unknown friend, return it";
|
||||
} else if (friendsManager->isInUnknownFriends(key)) {
|
||||
// qDebug() << key << "have been found in unknown friend, return it";
|
||||
return friendsManager->getUnknownFriendAtKey(key);
|
||||
}
|
||||
auto f = CoreModel::getInstance()->getCore()->findFriend(linphoneAddr);
|
||||
|
|
@ -141,20 +140,21 @@ std::shared_ptr<linphone::Friend> ToolModel::findFriendByAddress(std::shared_ptr
|
|||
if (friendsManager->isInUnknownFriends(key)) {
|
||||
friendsManager->removeUnknownFriend(key);
|
||||
}
|
||||
// qDebug() << "found friend, add to known map";
|
||||
// qDebug() << "found friend, add to known map";
|
||||
friendsManager->appendKnownFriend(linphoneAddr, f);
|
||||
}
|
||||
if (!f) {
|
||||
if (friendsManager->isInOtherAddresses(key)) {
|
||||
// qDebug() << "A magic search has already be done for address" << key << "and nothing was found, return";
|
||||
// qDebug() << "A magic search has already be done for address" << key << "and nothing was found,
|
||||
// return";
|
||||
return nullptr;
|
||||
}
|
||||
friendsManager->appendOtherAddress(key);
|
||||
// qDebug() << "Couldn't find friend" << linphoneAddr->asStringUriOnly() << "in core, use magic search";
|
||||
// qDebug() << "Couldn't find friend" << linphoneAddr->asStringUriOnly() << "in core, use magic search";
|
||||
CoreModel::getInstance()->searchInMagicSearch(Utils::coreStringToAppString(linphoneAddr->asStringUriOnly()),
|
||||
(int)linphone::MagicSearch::Source::LdapServers
|
||||
| (int)linphone::MagicSearch::Source::RemoteCardDAV
|
||||
, LinphoneEnums::MagicSearchAggregation::Friend, 50);
|
||||
(int)linphone::MagicSearch::Source::LdapServers |
|
||||
(int)linphone::MagicSearch::Source::RemoteCardDAV,
|
||||
LinphoneEnums::MagicSearchAggregation::Friend, 50);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
|
@ -378,6 +378,7 @@ std::shared_ptr<linphone::FriendList> ToolModel::getLdapFriendList() {
|
|||
|
||||
bool ToolModel::friendIsInFriendList(const std::shared_ptr<linphone::FriendList> &friendList,
|
||||
const std::shared_ptr<linphone::Friend> &f) {
|
||||
if (!friendList) return false;
|
||||
auto friends = friendList->getFriends();
|
||||
auto it = std::find_if(friends.begin(), friends.end(),
|
||||
[f](std::shared_ptr<linphone::Friend> linFriend) { return linFriend == f; });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue