diff --git a/bin/dbus/configurationmanager-introspec.xml b/bin/dbus/configurationmanager-introspec.xml index d7110bacf364dedfa4700067d14cabd9340c761e..fff47dc8470bb62c73ab4fdf87449fd391ef9c61 100644 --- a/bin/dbus/configurationmanager-introspec.xml +++ b/bin/dbus/configurationmanager-introspec.xml @@ -106,6 +106,23 @@ </arg> </method> + <method name="setAccountActive" tp:name-for-bindings="setAccountActive"> + <tp:docstring> + Set if this account is currently enabled (can be used). + It is only a runtime proprety with no impact on the "enabled" state of the account. + </tp:docstring> + <arg type="s" name="accountID" direction="in"> + <tp:docstring> + The account ID + </tp:docstring> + </arg> + <arg type="b" name="enable" direction="in"> + <tp:docstring> + <p>Set if enabled.</p> + </tp:docstring> + </arg> + </method> + <method name="setCredentials" tp:name-for-bindings="setCredentials"> <arg type="s" name="accountID" direction="in"> </arg> diff --git a/bin/dbus/dbusconfigurationmanager.cpp b/bin/dbus/dbusconfigurationmanager.cpp index 4cae44f8cb72857e6998275a5fdec852410cc496..22350c4d2304c9de57b3ab61f3091f1e3203420d 100644 --- a/bin/dbus/dbusconfigurationmanager.cpp +++ b/bin/dbus/dbusconfigurationmanager.cpp @@ -49,6 +49,12 @@ DBusConfigurationManager::setAccountDetails(const std::string& accountID, const DRing::setAccountDetails(accountID, details); } +void +DBusConfigurationManager::setAccountActive(const std::string& accountID, const bool& active) +{ + DRing::setAccountActive(accountID, active); +} + auto DBusConfigurationManager::getAccountTemplate(const std::string& accountType) -> decltype(DRing::getAccountTemplate(accountType)) { diff --git a/bin/dbus/dbusconfigurationmanager.h b/bin/dbus/dbusconfigurationmanager.h index c4ef3224e0444c561df09cf7f917ac069a39e98b..8a153fa8e8dc3152370e57b7901695eb1fd487da 100644 --- a/bin/dbus/dbusconfigurationmanager.h +++ b/bin/dbus/dbusconfigurationmanager.h @@ -59,6 +59,7 @@ class DBusConfigurationManager : std::map<std::string, std::string> getAccountDetails(const std::string& accountID); std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID); void setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details); + void setAccountActive(const std::string& accountID, const bool& active); std::map<std::string, std::string> getAccountTemplate(const std::string& accountType); std::string addAccount(const std::map<std::string, std::string>& details); void removeAccount(const std::string& accoundID); diff --git a/src/account.cpp b/src/account.cpp index 21ee0885a041df1504313d1e74df6d6e4e831305..9f83f3284470806776514595410818a5b0eb618b 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -304,7 +304,8 @@ std::map<std::string, std::string> Account::getVolatileAccountDetails() const { return { - {Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS, mapStateNumberToString(registrationState_)} + {Conf::CONFIG_ACCOUNT_REGISTRATION_STATUS, mapStateNumberToString(registrationState_)}, + {DRing::Account::VolatileProperties::ACTIVE, enabled_ ? TRUE_STR : FALSE_STR} }; } diff --git a/src/account.h b/src/account.h index c89531b8dfed2c268e5c9f569c27271657975301..d69af1194401982f93c3d3fa6c3f9916a402a0d0 100644 --- a/src/account.h +++ b/src/account.h @@ -153,19 +153,34 @@ class Account : public Serializable, public std::enable_shared_from_this<Account /** * Tell if the account is enable or not. - * @return true if enabled - * false otherwise + * @return true if enabled, false otherwise */ - bool isEnabled() const { + bool isEnabled() const noexcept { return enabled_; } - bool isVideoEnabled() const { - return videoEnabled_; + void setEnabled(bool enable) noexcept { + enabled_ = enable; } - void setEnabled(bool enable) { - enabled_ = enable; + /** + * Tell if the account is activated + * (can currently be used). + */ + bool isActive() const noexcept { + return active_; + } + + void setActive(bool active) noexcept { + active_ = active; + } + + bool isUsable() const noexcept { + return enabled_ and active_; + } + + bool isVideoEnabled() const noexcept { + return videoEnabled_; } /** @@ -340,12 +355,19 @@ class Account : public Serializable, public std::enable_shared_from_this<Account std::string alias_; /** - * Tells if the link is enabled, active. + * Tells if the account is enabled. * This implies the link will be initialized on startup. * Modified by the configuration (key: ENABLED) */ bool enabled_; + /** + * Tells if the account is active now. + * This allows doRegister to be called. + * When an account is unactivated, doUnregister must be called. + */ + bool active_ {true}; + /* If true, automatically answer calls to this account */ bool autoAnswerEnabled_; diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index 18ae6989a9f1c8905e57fc6bf44e89f889d50c7f..e97159ef8da27fc76c016cb71899deac61686f01 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -258,6 +258,12 @@ setAccountDetails(const std::string& accountID, const std::map<std::string, std: ring::Manager::instance().setAccountDetails(accountID, details); } +void +setAccountActive(const std::string& accountID, bool enable) +{ + ring::Manager::instance().setAccountActive(accountID, enable); +} + void sendRegister(const std::string& accountID, bool enable) { diff --git a/src/dring/account_const.h b/src/dring/account_const.h index b73de020a49fbd113f2b7190c40dc7832fe52436..379b4d4b4914a003cd41f9c4b293c18d9d1cb0ad 100644 --- a/src/dring/account_const.h +++ b/src/dring/account_const.h @@ -60,6 +60,8 @@ constexpr static const char REQUEST_TIMEOUT [] = "Request Timeout"; namespace VolatileProperties { +constexpr static const char ACTIVE [] = "Account.active"; + // Volatile parameters namespace Registration { diff --git a/src/dring/configurationmanager_interface.h b/src/dring/configurationmanager_interface.h index 9786ed8e6bbe779d7a9c37fd752c2188f479b982..8acc248a4f33d08f9379ebdf6424d904e16fcf07 100644 --- a/src/dring/configurationmanager_interface.h +++ b/src/dring/configurationmanager_interface.h @@ -41,9 +41,11 @@ void registerConfHandlers(const std::map<std::string, std::shared_ptr<CallbackWr std::map<std::string, std::string> getAccountDetails(const std::string& accountID); std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID); void setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details); +void setAccountActive(const std::string& accountID, bool active); std::map<std::string, std::string> getAccountTemplate(const std::string& accountType); std::string addAccount(const std::map<std::string, std::string>& details); void removeAccount(const std::string& accountID); +void setAccountEnabled(const std::string& accountID, bool enable); std::vector<std::string> getAccountList(); void sendRegister(const std::string& accountID, bool enable); void registerAllAccounts(void); diff --git a/src/manager.cpp b/src/manager.cpp index f413a6d487dc1a11c8b000d2760a9c8beccc3da2..5a5e59b30db5177a60eebe07a8ccdd7b08496486 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2382,9 +2382,9 @@ Manager::setAccountDetails(const std::string& accountID, // Serialize configuration to disk once it is done saveConfig(); - if (account->isEnabled()) { + if (account->isUsable()) account->doRegister(); - } else + else account->doUnregister(); // Update account details to the client side @@ -2668,9 +2668,8 @@ Manager::registerAccounts() a->loadConfig(); - if (a->isEnabled()) { + if (a->isUsable()) a->doRegister(); - } } } @@ -2710,6 +2709,21 @@ Manager::sendTextMessage(const std::string& accountID, const std::string& to, co acc->sendTextMessage(to, message); } +void +Manager::setAccountActive(const std::string& accountID, bool active) +{ + const auto acc = getAccount(accountID); + if (!acc || acc->isActive() == active) + return; + acc->setActive(active); + if (acc->isEnabled()) { + if (active) + acc->doRegister(); + else + acc->doUnregister(); + } +} + std::shared_ptr<AudioLayer> Manager::getAudioDriver() { @@ -2748,7 +2762,7 @@ Manager::newOutgoingCall(const std::string& toUrl, } else RING_WARN("IP Url detected, using IP2IP account"); - if (!account) { + if (!account or !account->isUsable()) { RING_ERR("No suitable account found to create outgoing call"); return nullptr; } diff --git a/src/manager.h b/src/manager.h index 74bea6c748d218fa15de135c08bfb2b8b9d2b4ad..21c3d3f2eb9c30ae6e1cfba30f51e74646ad8e6e 100644 --- a/src/manager.h +++ b/src/manager.h @@ -490,6 +490,8 @@ class Manager { void setAccountDetails(const std::string& accountID, const std::map<std::string, ::std::string > &details); + void setAccountActive(const std::string& accountID, bool active); + /** * Add a new account, and give it a new account ID automatically * @param details The new account parameters diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp index cfa403e921ea88afbb0f314854f26b8df3309578..7a3007682ba066a3e015548b55c936ab30717a28 100644 --- a/src/ringdht/ringaccount.cpp +++ b/src/ringdht/ringaccount.cpp @@ -679,8 +679,8 @@ bool RingAccount::mapPortUPnP() void RingAccount::doRegister() { - if (not isEnabled()) { - RING_WARN("Account must be enabled to register, ignoring"); + if (not isUsable()) { + RING_WARN("Account must be enabled and active to register, ignoring"); return; } diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp index bd85ee756c77e163464b83cf29353b15fd2e15b6..3196ddddedee425655318b9a175178e08d598900 100644 --- a/src/sip/sipaccount.cpp +++ b/src/sip/sipaccount.cpp @@ -716,8 +716,8 @@ bool SIPAccount::mapPortUPnP() void SIPAccount::doRegister() { - if (not isEnabled()) { - RING_WARN("Account must be enabled to register, ignoring"); + if (not isUsable()) { + RING_WARN("Account must be enabled and active to register, ignoring"); return; } @@ -943,8 +943,8 @@ void SIPAccount::stopKeepAliveTimer() void SIPAccount::sendRegister() { - if (not isEnabled()) { - RING_WARN("Account must be enabled to register, ignoring"); + if (not isUsable()) { + RING_WARN("Account must be enabled and active to register, ignoring"); return; } @@ -1130,6 +1130,7 @@ SIPAccount::sendUnregister() // Make sure to cancel any ongoing timers before unregister stopKeepAliveTimer(); + setRegister(false); pjsip_regc *regc = getRegistrationInfo(); if (!regc) @@ -1145,8 +1146,6 @@ SIPAccount::sendUnregister() sip_utils::sip_strerror(status).c_str()); throw VoipLinkException("Unable to send request to unregister sip account"); } - - setRegister(false); } #if HAVE_TLS @@ -2024,7 +2023,7 @@ SIPAccount::autoReregTimerCb(pj_timer_heap_t * /*th*/, pj_timer_entry *te) void SIPAccount::scheduleReregistration(pjsip_endpoint *endpt) { - if (!isEnabled()) + if (!isUsable()) return; /* Cancel any re-registration timer */