Commit 9d9ef2a8 authored by Adrien Béraud's avatar Adrien Béraud Committed by Guillaume Roguez

sipaccountbase: add common matches() internal API

Cleanup and factorise incoming call matching API.

Change-Id: I4b6ceb24372a189c3bf3b5bbbaf97c59912140ec
Reviewed-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent d16dde17
......@@ -181,7 +181,7 @@ class RingAccount : public SIPAccountBase {
}
/* Returns true if the username and/or hostname match this account */
MatchRank matches(const std::string &username, const std::string &hostname) const;
MatchRank matches(const std::string &username, const std::string &hostname) const override;
/**
* Activate the module.
......
......@@ -1280,9 +1280,9 @@ void SIPAccount::loadConfig()
transportType_ = PJSIP_TRANSPORT_UDP;
}
bool SIPAccount::fullMatch(const std::string& username, const std::string& hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const
bool SIPAccount::fullMatch(const std::string& username, const std::string& hostname) const
{
return userMatch(username) and hostnameMatch(hostname, endpt, pool);
return userMatch(username) and hostnameMatch(hostname);
}
bool SIPAccount::userMatch(const std::string& username) const
......@@ -1290,7 +1290,7 @@ bool SIPAccount::userMatch(const std::string& username) const
return !username.empty() and username == username_;
}
bool SIPAccount::hostnameMatch(const std::string& hostname, pjsip_endpoint * /*endpt*/, pj_pool_t * /*pool*/) const
bool SIPAccount::hostnameMatch(const std::string& hostname) const
{
if (hostname == hostname_)
return true;
......@@ -1299,7 +1299,7 @@ bool SIPAccount::hostnameMatch(const std::string& hostname, pjsip_endpoint * /*e
return ip_utils::haveCommonAddr(a, b);
}
bool SIPAccount::proxyMatch(const std::string& hostname, pjsip_endpoint * /*endpt*/, pj_pool_t * /*pool*/) const
bool SIPAccount::proxyMatch(const std::string& hostname) const
{
if (hostname == serviceRoute_)
return true;
......@@ -1751,19 +1751,18 @@ SIPAccount::supportPresence(int function, bool enabled)
}
MatchRank
SIPAccount::matches(const std::string &userName, const std::string &server,
pjsip_endpoint *endpt, pj_pool_t *pool) const
SIPAccount::matches(const std::string &userName, const std::string &server) const
{
if (fullMatch(userName, server, endpt, pool)) {
if (fullMatch(userName, server)) {
RING_DBG("Matching account id in request is a fullmatch %s@%s", userName.c_str(), server.c_str());
return MatchRank::FULL;
} else if (hostnameMatch(server, endpt, pool)) {
} else if (hostnameMatch(server)) {
RING_DBG("Matching account id in request with hostname %s", server.c_str());
return MatchRank::PARTIAL;
} else if (userMatch(userName)) {
RING_DBG("Matching account id in request with username %s", userName.c_str());
return MatchRank::PARTIAL;
} else if (proxyMatch(server, endpt, pool)) {
} else if (proxyMatch(server)) {
RING_DBG("Matching account id in request with proxy %s", server.c_str());
return MatchRank::PARTIAL;
} else {
......
......@@ -443,7 +443,7 @@ class SIPAccount : public SIPAccountBase {
pjsip_tpselector getTransportSelector();
/* Returns true if the username and/or hostname match this account */
MatchRank matches(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
MatchRank matches(const std::string &username, const std::string &hostname) const override;
/**
* Presence management
......@@ -521,10 +521,10 @@ class SIPAccount : public SIPAccountBase {
void usePublishedAddressPortInVIA();
void useUPnPAddressPortInVIA();
bool fullMatch(const std::string &username, const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
bool fullMatch(const std::string &username, const std::string &hostname) const;
bool userMatch(const std::string &username) const;
bool hostnameMatch(const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
bool proxyMatch(const std::string &hostname, pjsip_endpoint *endpt, pj_pool_t *pool) const;
bool hostnameMatch(const std::string &hostname) const;
bool proxyMatch(const std::string &hostname) const;
bool isSrtpEnabled() const {
return srtpKeyExchange_ != sip_utils::KeyExchangeProtocol::NONE;
......
......@@ -247,6 +247,9 @@ public:
void onTextMessage(const std::string& from, const std::map<std::string, std::string>& payloads);
/* Returns true if the username and/or hostname match this account */
virtual MatchRank matches(const std::string &username, const std::string &hostname) const = 0;
void connectivityChanged() override {};
protected:
......
......@@ -651,7 +651,7 @@ SIPVoIPLink::guessAccount(const std::string& userName,
for (const auto& account : Manager::instance().getAllAccounts<SIPAccount>()) {
if (!account)
continue;
const MatchRank match(account->matches(userName, server, endpt_, pool_.get()));
const MatchRank match(account->matches(userName, server));
// return right away if this is a full match
if (match == MatchRank::FULL) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment