diff --git a/src/manager.cpp b/src/manager.cpp index 702f7630b52443df8233a768ad4df899508017d9..f389070faf1363bd0976ece3bf93764028b156f1 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2321,22 +2321,11 @@ Manager::setAccountsOrder(const std::string& order) std::vector<std::string> Manager::getAccountList() const { - auto account_order = loadAccountOrder(); - // Concatenate all account pointers in a single map - const auto& allAccounts = accountFactory_.getAllAccounts(); std::vector<std::string> v; - v.reserve(allAccounts.size()); - - // If no order has been set, load the default one ie according to the creation date. - if (account_order.empty()) { - for (const auto &account : allAccounts) - v.emplace_back(account->getAccountID()); - } else { - for (const auto& id : account_order) { - if (accountFactory_.hasAccount(id)) - v.push_back(id); - } + v.reserve(accountCount()); + for (const auto &account : getAllAccounts()) { + v.emplace_back(account->getAccountID()); } return v; diff --git a/src/manager.h b/src/manager.h index 1e2e8014aa347b62eafd4bc764ffbe97f2fb9d71..a792490c7634da2bee7c3c044b636e8393908d05 100644 --- a/src/manager.h +++ b/src/manager.h @@ -885,7 +885,7 @@ class Manager { bool hasCurrentCall() const; /** - * Get an account pointer, looks for both SIP and IAX + * Get an account pointer, looks for account of type T * @param accountID account ID to get * @return std::shared_ptr<Account> Shared pointer on an Account instance or nullptr if not found */ @@ -894,9 +894,26 @@ class Manager { return accountFactory_.getAccount<T>(accountID); } + /** + * Get a list of account pointers of type T (baseclass Account) + * @return a sorted vector of all accounts of type T + */ template <class T=Account> - std::vector<std::shared_ptr<T> > getAllAccounts() const { - return accountFactory_.getAllAccounts<T>(); + std::vector<std::shared_ptr<T>> getAllAccounts() const { + auto account_order = loadAccountOrder(); + std::vector<std::shared_ptr<T>> accountList; + + // If no order has been set, load the default one ie according to the creation date. + if (account_order.empty()) { + for (const auto &account : accountFactory_.getAllAccounts<T>()) + accountList.emplace_back(account); + } else { + for (const auto& id : account_order) { + if (auto acc = accountFactory_.getAccount<T>(id)) + accountList.push_back(acc); + } + } + return accountList; } template <class T=Account> diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index 7efce94e64dc11ab6c76b12813a5f5796f515aac..c17ea35f23dfb969fa424b634dcc9b3647890d40 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -633,7 +633,8 @@ SIPVoIPLink::guessAccount(const std::string& userName, RING_DBG("username = %s, server = %s, from = %s", userName.c_str(), server.c_str(), fromUri.c_str()); // Try to find the account id from username and server name by full match - std::shared_ptr<SIPAccountBase> result {}; + std::shared_ptr<SIPAccountBase> result; + std::shared_ptr<SIPAccountBase> IP2IPAccount; MatchRank best = MatchRank::NONE; #if HAVE_DHT @@ -665,10 +666,13 @@ SIPVoIPLink::guessAccount(const std::string& userName, } else if (match > best) { best = match; result = account; + } else if (!IP2IPAccount && account->isIP2IP()) { + // Allow IP2IP calls if an account exists for this type of calls + IP2IPAccount = account; } } - return result; + return result ? result : IP2IPAccount; } // Called from EventThread::run (not main thread)