Commit b21a5664 authored by Adrien Béraud's avatar Adrien Béraud Committed by Gerrit Code Review

merge sipRegistrationStateChanged signal with registrationStateChanged

Refs #68868

Change-Id: Iadd5f7a71d22ae265936a0f3a40f8c18e18a6583
parent f481aeaa
......@@ -530,32 +530,17 @@
<signal name="accountsChanged" tp:name-for-bindings="accountsChanged">
</signal>
<!-- FIXME: we should rethink these two signals -->
<!-- Used by IAX and SIP accounts -->
<signal name="registrationStateChanged" tp:name-for-bindings="registrationStateChanged">
<arg type="s" name="accountID"/>
<arg type="i" name="registration_state"/>
</signal>
<!-- Only used by SIP accounts, data is directly from pjsip -->
<signal name="sipRegistrationStateChanged" tp:name-for-bindings="sipRegistrationStateChanged">
<tp:docstring>
<p>Account state changed, Ring received a notification from registrar.</p>
</tp:docstring>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
<arg type="s" name="accountID" >
<arg type="i" name="registrationState"/>
<arg type="i" name="registrationDetail">
<tp:docstring>
The account ID
The optional account-type specific message code. 0 when not available.
</tp:docstring>
</arg>
<arg type="s" name="state">
<tp:docstring>
Description string
</tp:docstring>
</arg>
<arg type="i" name="code">
<arg type="s" name="registrationDetailStr">
<tp:docstring>
The SIP message code
The optional account-type specific message string. Empty string when not available.
</tp:docstring>
</arg>
</signal>
......
......@@ -181,8 +181,7 @@ DBusClient::initLibrary(int sflphFlags)
exportable_callback<ConfigurationSignal::VolumeChanged>(bind(&DBusConfigurationManager::volumeChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::AccountsChanged>(bind(&DBusConfigurationManager::accountsChanged, confM)),
exportable_callback<ConfigurationSignal::StunStatusFailed>(bind(&DBusConfigurationManager::stunStatusFailure, confM, _1)),
exportable_callback<ConfigurationSignal::RegistrationStateChanged>(bind(&DBusConfigurationManager::registrationStateChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::SipRegistrationStateChanged>(bind(&DBusConfigurationManager::sipRegistrationStateChanged, confM, _1, _2, _3)),
exportable_callback<ConfigurationSignal::RegistrationStateChanged>(bind(&DBusConfigurationManager::registrationStateChanged, confM, _1, _2, _3, _4)),
exportable_callback<ConfigurationSignal::VolatileDetailsChanged>(bind(&DBusConfigurationManager::volatileAccountDetailsChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::Error>(bind(&DBusConfigurationManager::errorAlert, confM, _1)),
};
......
......@@ -146,16 +146,20 @@ Account::freeAccount()
}
void
Account::setRegistrationState(RegistrationState state)
Account::setRegistrationState(RegistrationState state, unsigned detail_code, const std::string& detail_str)
{
if (state != registrationState_) {
registrationState_ = state;
// Notify the client
emitSignal<DRing::ConfigurationSignal::RegistrationStateChanged>(accountID_,
static_cast<int32_t>(registrationState_));
emitSignal<DRing::ConfigurationSignal::VolatileDetailsChanged>(accountID_,
getVolatileAccountDetails());
emitSignal<DRing::ConfigurationSignal::RegistrationStateChanged>(
accountID_,
static_cast<int32_t>(registrationState_),
detail_code,
detail_str);
emitSignal<DRing::ConfigurationSignal::VolatileDetailsChanged>(
accountID_,
getVolatileAccountDetails());
}
}
......
......@@ -178,7 +178,7 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
* Set the registration state of the specified link
* @param state The registration state of underlying VoIPLink
*/
void setRegistrationState(RegistrationState state);
virtual void setRegistrationState(RegistrationState state, unsigned detail_code=0, const std::string& detail_str={});
/* They should be treated like macro definitions by the C++ compiler */
std::string getUsername() const {
......
......@@ -66,7 +66,6 @@ getSignalHandlers()
exported_callback<DRing::ConfigurationSignal::AccountsChanged>(),
exported_callback<DRing::ConfigurationSignal::StunStatusFailed>(),
exported_callback<DRing::ConfigurationSignal::RegistrationStateChanged>(),
exported_callback<DRing::ConfigurationSignal::SipRegistrationStateChanged>(),
exported_callback<DRing::ConfigurationSignal::VolatileDetailsChanged>(),
exported_callback<DRing::ConfigurationSignal::Error>(),
......
......@@ -154,11 +154,7 @@ struct ConfigurationSignal {
};
struct RegistrationStateChanged {
constexpr static const char* name = "RegistrationStateChanged";
using cb_type = void(const std::string& /*account_id*/, int /*state*/);
};
struct SipRegistrationStateChanged {
constexpr static const char* name = "SipRegistrationStateChanged";
using cb_type = void(const std::string& /*account_id*/, const std::string& /*state*/, int /*code*/);
using cb_type = void(const std::string& /*account_id*/, int /*state*/, int /*detailsCode*/, const std::string& /*detailsStr*/);
};
struct VolatileDetailsChanged {
constexpr static const char* name = "VolatileDetailsChanged";
......
......@@ -282,7 +282,7 @@ SIPAccount::onTransportStateChanged(pjsip_transport_state state, const pjsip_tra
transportStatus_ = PJSIP_SC_SERVICE_UNAVAILABLE;
transportError_ = "";
}
setRegistrationState(RegistrationState::ERROR_GENERIC);
setRegistrationState(RegistrationState::ERROR_GENERIC, PJSIP_SC_TSX_TRANSPORT_ERROR);
setTransport();
}
else {
......@@ -677,17 +677,6 @@ SIPAccount::getAccountDetails() const
}
}
std::string registrationStateCode;
std::string registrationStateDescription;
if (isIP2IP())
registrationStateDescription = "Direct IP call";
else {
registrationStateCode = ring::to_string(registrationStateDetailed_.first);
registrationStateDescription = registrationStateDetailed_.second;
}
a.emplace(Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, registrationStateCode);
a.emplace(Conf::CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, registrationStateDescription);
a.emplace(Conf::CONFIG_LOCAL_PORT, ring::to_string(localPort_));
a.emplace(Conf::CONFIG_ACCOUNT_ROUTESET, serviceRoute_);
a.emplace(Conf::CONFIG_ACCOUNT_REGISTRATION_EXPIRE, ring::to_string(registrationExpire_));
......@@ -698,8 +687,6 @@ SIPAccount::getAccountDetails() const
a.emplace(Conf::CONFIG_PRESENCE_ENABLED, presence_ and presence_->isEnabled()? TRUE_STR : FALSE_STR);
a.emplace(Conf::CONFIG_PRESENCE_PUBLISH_SUPPORTED, presence_ and presence_->isSupported(PRESENCE_FUNCTION_PUBLISH)? TRUE_STR : FALSE_STR);
a.emplace(Conf::CONFIG_PRESENCE_SUBSCRIBE_SUPPORTED, presence_ and presence_->isSupported(PRESENCE_FUNCTION_SUBSCRIBE)? TRUE_STR : FALSE_STR);
a.emplace(Conf::CONFIG_PRESENCE_STATUS, presence_ and presence_->isOnline()? TRUE_STR : FALSE_STR);
a.emplace(Conf::CONFIG_PRESENCE_NOTE, presence_ ? presence_->getNote() : " ");
auto tlsSettings(getTlsSettings());
a.insert(tlsSettings.begin(), tlsSettings.end());
......@@ -811,7 +798,7 @@ void SIPAccount::doRegister1_()
auto this_ = std::static_pointer_cast<SIPAccount>(shared).get();
if (host_ips.empty()) {
RING_ERR("Can't resolve hostname for registration.");
this_->setRegistrationState(RegistrationState::ERROR_GENERIC);
this_->setRegistrationState(RegistrationState::ERROR_GENERIC, PJSIP_SC_NOT_FOUND);
return;
}
this_->hostIp_ = host_ips[0];
......@@ -829,7 +816,7 @@ void SIPAccount::doRegister2_()
ipv6 = ip_utils::getInterfaceAddr(interface_).isIpv6();
#endif
} else if (!hostIp_) {
setRegistrationState(RegistrationState::ERROR_GENERIC);
setRegistrationState(RegistrationState::ERROR_GENERIC, PJSIP_SC_NOT_FOUND);
RING_ERR("Hostname not resolved.");
return;
}
......@@ -1077,6 +1064,7 @@ SIPAccount::onRegister(pjsip_regc_cbparam *param)
RING_ERR("SIP registration error %d", param->status);
destroyRegistrationInfo();
stopKeepAliveTimer();
setRegistrationState(RegistrationState::ERROR_GENERIC, param->code);
} else if (param->code < 0 || param->code >= 300) {
RING_ERR("SIP registration failed, status=%d (%.*s)",
param->code, (int)param->reason.slen, param->reason.ptr);
......@@ -1084,19 +1072,19 @@ SIPAccount::onRegister(pjsip_regc_cbparam *param)
stopKeepAliveTimer();
switch (param->code) {
case PJSIP_SC_FORBIDDEN:
setRegistrationState(RegistrationState::ERROR_AUTH);
setRegistrationState(RegistrationState::ERROR_AUTH, param->code);
break;
case PJSIP_SC_NOT_FOUND:
setRegistrationState(RegistrationState::ERROR_HOST);
setRegistrationState(RegistrationState::ERROR_HOST, param->code);
break;
case PJSIP_SC_REQUEST_TIMEOUT:
setRegistrationState(RegistrationState::ERROR_HOST);
setRegistrationState(RegistrationState::ERROR_HOST, param->code);
break;
case PJSIP_SC_SERVICE_UNAVAILABLE:
setRegistrationState(RegistrationState::ERROR_SERVICE_UNAVAILABLE);
setRegistrationState(RegistrationState::ERROR_SERVICE_UNAVAILABLE, param->code);
break;
default:
setRegistrationState(RegistrationState::ERROR_GENERIC);
setRegistrationState(RegistrationState::ERROR_GENERIC, param->code);
}
} else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) {
......@@ -1108,7 +1096,7 @@ SIPAccount::onRegister(pjsip_regc_cbparam *param)
/* Stop keep-alive timer if any. */
stopKeepAliveTimer();
RING_DBG("Unregistration success");
setRegistrationState(RegistrationState::UNREGISTERED);
setRegistrationState(RegistrationState::UNREGISTERED, param->code);
} else {
/* TODO Check and update SIP outbound status first, since the result
* will determine if we should update re-registration
......@@ -1127,7 +1115,7 @@ SIPAccount::onRegister(pjsip_regc_cbparam *param)
if (isKeepAliveEnabled())
startKeepAliveTimer();
setRegistrationState(RegistrationState::REGISTERED);
setRegistrationState(RegistrationState::REGISTERED, param->code);
}
}
......@@ -1149,19 +1137,7 @@ SIPAccount::onRegister(pjsip_regc_cbparam *param)
if (PJSIP_IS_STATUS_IN_CLASS(param->code, 600))
scheduleReregistration(link_->getEndpoint());
}
const pj_str_t *description = pjsip_get_status_text(param->code);
if (param->code && description) {
std::string state(description->ptr, description->slen);
emitSignal<DRing::ConfigurationSignal::SipRegistrationStateChanged>(getAccountID(), state, param->code);
emitSignal<DRing::ConfigurationSignal::VolatileDetailsChanged>(accountID_, getVolatileAccountDetails());
std::pair<int, std::string> details(param->code, state);
// TODO: there id a race condition for this ressource when closing the application
setRegistrationStateDetailed(details);
setRegistrationExpire(param->expiration);
}
setRegistrationExpire(param->expiration);
}
void
......@@ -1702,6 +1678,17 @@ SIPAccount::getCredentials() const
return credentials_;
}
void
SIPAccount::setRegistrationState(RegistrationState state, unsigned details_code)
{
std::string details_str;
const pj_str_t *description = pjsip_get_status_text(details_code);
if (description)
details_str = {description->ptr, (size_t)description->slen};
setRegistrationStateDetailed({details_code, details_str});
Account::setRegistrationState(state, details_code, details_str);
}
std::string SIPAccount::getUserAgentName() const
{
if (not hasCustomUserAgent_ or userAgent_.empty())
......
......@@ -220,6 +220,8 @@ class SIPAccount : public SIPAccountBase {
const std::vector<std::map<std::string, std::string> > &
getCredentials() const;
void setRegistrationState(RegistrationState state, unsigned code=0);
/**
* A client sendings a REGISTER request MAY suggest an expiration
* interval that indicates how long the client would like the
......
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