diff --git a/src/api/account.h b/src/api/account.h index d36abdd007916f99e193bb03c9853b730562166a..6f9b6c684d48dc4f4ce48e4635f461eb2c8495cf 100644 --- a/src/api/account.h +++ b/src/api/account.h @@ -25,6 +25,9 @@ // Data #include "profile.h" +// old LRC +#include "typedefs.h" + namespace lrc { @@ -74,20 +77,120 @@ to_status(const std::string& type) #pragma pop_macro("REGISTERED") +struct ConfProperties_t { + std::string displayName; + std::string mailbox; + std::string dtmfType; + bool autoAnswer; + int activeCallLimit; + std::string hostname; + std::string username; + std::string routeset; + std::string password; + std::string realm; + std::string localInterface; + bool publishedSameAsLocal; + int localPort; + int publishedPort; + std::string publishedAddress; + std::string userAgent; + bool upnpEnabled; + bool hasCustomUserAgent; + bool allowIncomingFromHistory; + bool allowIncomingFromContact; + bool allowIncomingFromTrusted; + std::string archivePassword; + bool archiveHasPassword; + std::string archivePath; + std::string archivePin; + // in NewDeviceModel: deviceID; + // in NewDeviceModel: deviceName; + bool proxyEnabled; + std::string proxyServer; + std::string proxyPushToken; + struct Audio_t { + int audioPortMax; + int audioPortMin; + } Audio; + struct Video_t { + bool videoEnabled; + int videoPortMax; + int videoPortMin; + } Video; + struct STUN_t { + std::string server; + bool enable; + } STUN; + struct TURN_t { + std::string server; + bool enable; + std::string username; + std::string password; + std::string realm; + } TURN; + struct Presence_t { + bool presencePublishSupported; + bool presenceSubscribeSupported; + bool presenceEnabled; + } Presence; + struct Ringtone_t { + std::string ringtonePath; + bool ringtoneEnabled; + } Ringtone; + struct SRTP_t { + std::string keyExchange; + bool enable; + bool rtpFallback; + } SRTP; + struct TLS_t { + int listenerPort; + bool enable; + int port; + std::string certificateListFile; + std::string certificateFile; + std::string privateKeyFile; + std::string password; + std::string method; + std::string ciphers; + std::string serverName; + bool verifyServer; + bool verifyClient; + bool requireClientCertificate; + int negotiationTimeoutSec; + } TLS; + struct DHT_t { + int port; + bool PublicInCalls; + bool AllowFromTrusted; + } DHT; + struct RingNS_t { + std::string uri; + std::string account; + } RingNS; + + MapStringString toDetails() const; +}; + struct Info { - std::string id; - std::string registeredName; - bool enabled; bool freeable = false; bool valid = true; + std::string registeredName; Status status = account::Status::INVALID; - profile::Info profileInfo; std::unique_ptr<lrc::api::NewCallModel> callModel; std::unique_ptr<lrc::api::ContactModel> contactModel; std::unique_ptr<lrc::api::ConversationModel> conversationModel; std::unique_ptr<lrc::api::NewDeviceModel> deviceModel; NewAccountModel* accountModel {nullptr}; + + // daemon config + std::string id; + profile::Info profileInfo; // contains: type, alias + bool enabled; + ConfProperties_t confProperties; + + // load/save + void fromDetails(const MapStringString& details); }; } // namespace account diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h index 1ae083135531fd18a6ab66643de3d353808eb566..6b7246c5ed5232102845ad41a7f051527dafa932 100644 --- a/src/api/newaccountmodel.h +++ b/src/api/newaccountmodel.h @@ -45,7 +45,10 @@ namespace api class Lrc; class BehaviorController; -namespace account { struct Info; } +namespace account { + struct ConfProperties_t; + struct Info; +} /** * @brief Class that manages account information. @@ -75,7 +78,20 @@ public: /** * flag account corresponding to passed id as freeable. */ - void flagFreeable(const std::string& accountID) const; + void flagFreeable(const std::string& accountId) const; + /** + * saves account config to .yml + * @param accountId. + * @param reference to the confProperties + */ + void setAccountConfig(const std::string& accountID, + const account::ConfProperties_t& confProperties) const; + /** + * gets a copy of the accounts config + * @param accountId. + * @return an account::Info::ConfProperties_t structure. + */ + account::ConfProperties_t getAccountConfig(const std::string& accountId) const; /** * Call exportToFile from the daemon * @param accountId @@ -99,6 +115,12 @@ public: bool changeAccountPassword(const std::string& accountId, const std::string& currentPassword, const std::string& newPassword) const; + /** + * Enable or disable an account + * @param accountId + * @param enable + */ + void enableAccount(const std::string& accountId, bool enabled); Q_SIGNALS: /** diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp index 88739629a043f855039c71274f0338d362ab786b..ceca711444a5cf77b86e2473bdeb945318fda3c2 100644 --- a/src/callbackshandler.cpp +++ b/src/callbackshandler.cpp @@ -79,6 +79,11 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent) this, &CallbacksHandler::slotRegisteredNameFound); + connect(&ConfigurationManager::instance(), + &ConfigurationManagerInterface::accountDetailsChanged, + this, + &CallbacksHandler::slotAccountDetailsChanged); + connect(&ConfigurationManager::instance(), &ConfigurationManagerInterface::registrationStateChanged, this, @@ -222,6 +227,13 @@ CallbacksHandler::slotCallStateChanged(const QString& callId, const QString& sta emit callStateChanged(callId.toStdString(), state.toStdString(), code); } +void +CallbacksHandler::slotAccountDetailsChanged(const QString& accountId, + const MapStringString& details) +{ + emit accountDetailsChanged(accountId.toStdString(), convertMap(details)); +} + void CallbacksHandler::slotRegistrationStateChanged(const QString& accountId, const QString& registration_state, diff --git a/src/callbackshandler.h b/src/callbackshandler.h index f9dda0de9a3bf260f9b0f49c3a379b4bfb58228c..cd022132bf68b1da8f50d8050f0b36eee720d786 100644 --- a/src/callbackshandler.h +++ b/src/callbackshandler.h @@ -30,6 +30,7 @@ #include "typedefs.h" #include "namedirectory.h" #include "api/datatransfer.h" +#include "qtwrapper/conversions_wrap.hpp" namespace lrc { @@ -104,6 +105,13 @@ Q_SIGNALS: * @param code */ void callStateChanged(const std::string& callId, const std::string &state, int code); + /** + * Connect this signal to know when the account details have changed + * @param accountId the one who changes + * @param details the new details + */ + void accountDetailsChanged(const std::string& accountId, + const std::map<std::string,std::string>& details); /** * Connect this signal to know when the account status changed * @param accountId the one who changes @@ -237,6 +245,13 @@ private Q_SLOTS: void slotIncomingContactRequest(const QString& accountId, const QString& ringId, const QByteArray& payload, time_t time); + /** + * Emit accountDetailsChanged + * @param accountId + * @param details + */ + void slotAccountDetailsChanged(const QString& accountId, + const MapStringString& details); /** * Emit accountStatusChanged * @param accountId diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index 4c131b086770a4988c815eb1d3dce0da323a4cfe..da7bf6b14fdcede852fee37c01ba9cca21caabfa 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -18,26 +18,32 @@ ***************************************************************************/ #include "api/newaccountmodel.h" +// daemon +#include <account_const.h> -// LRC -#include "api/account.h" -#include "api/behaviorcontroller.h" -#include "api/contactmodel.h" -#include "api/conversationmodel.h" +// new LRC #include "api/lrc.h" #include "api/newcallmodel.h" +#include "api/contactmodel.h" +#include "api/conversationmodel.h" #include "api/newdevicemodel.h" +#include "api/account.h" +#include "api/behaviorcontroller.h" #include "authority/databasehelper.h" #include "callbackshandler.h" #include "database.h" +// old LRC #include "accountmodel.h" #include "profilemodel.h" #include "profile.h" +#include "qtwrapper/conversions_wrap.hpp" // Dbus #include "dbus/configurationmanager.h" +#include <iostream> + namespace lrc { @@ -79,6 +85,11 @@ public Q_SLOTS: * @param status */ void slotAccountStatusChanged(const std::string& accountID, const api::account::Status status); + /** + * @param accountId + * @param details + */ + void slotAccountDetailsChanged(const std::string& accountID, const std::map<std::string, std::string>& details); /** * Emit accountRemoved. * @param account @@ -116,17 +127,47 @@ NewAccountModel::getAccountList() const } void -NewAccountModel::flagFreeable(const std::string& accountId) const +NewAccountModel::setAccountConfig(const std::string& accountId, + const account::ConfProperties_t& confProperties) const +{ + auto accountInfoEntry = pimpl_->accounts.find(accountId); + if (accountInfoEntry == pimpl_->accounts.end()) { + throw std::out_of_range("NewAccountModel::save, can't find " + accountId); + } + auto& accountInfo = accountInfoEntry->second; + auto& configurationManager = ConfigurationManager::instance(); + MapStringString details = confProperties.toDetails(); + // Set values from Info. No need to include ID and TYPE. SIP accounts may modify the USERNAME + // TODO: move these into the ConfProperties_t struct ? + using namespace DRing::Account; + qDebug("UPNP_ENABLED: %s\n", details[ConfProperties::UPNP_ENABLED].toStdString().c_str()); + details[ConfProperties::ENABLED] = toQString(accountInfo.enabled); + details[ConfProperties::ALIAS] = toQString(accountInfo.profileInfo.alias); + details[ConfProperties::TYPE] = (accountInfo.profileInfo.type == profile::Type::RING) ? QString(ProtocolNames::RING) : QString(ProtocolNames::SIP); + details[ConfProperties::USERNAME] = toQString(accountInfo.profileInfo.uri).prepend((accountInfo.profileInfo.type == profile::Type::RING) ? "ring:" : ""); + configurationManager.setAccountDetails(QString::fromStdString(accountId), details); +} + +account::ConfProperties_t +NewAccountModel::getAccountConfig(const std::string& accountId) const { auto accountInfo = pimpl_->accounts.find(accountId); - if (accountInfo == pimpl_->accounts.end()) - throw std::out_of_range("NewAccountModel::flagFreeable, can't find " + accountId); + if (accountInfo == pimpl_->accounts.end()) { + throw std::out_of_range("NewAccountModel::getAccountConfig, can't find " + accountId); + } - { - std::lock_guard<std::mutex> lock(pimpl_->m_mutex_account_removal); - accountInfo->second.freeable = true; + return accountInfo->second.confProperties; +} + + +void +NewAccountModel::enableAccount(const std::string& accountId, bool enabled) +{ + auto accountInfo = pimpl_->accounts.find(accountId); + if (accountInfo == pimpl_->accounts.end()) { + throw std::out_of_range("NewAccountModel::getAccountConfig, can't find " + accountId); } - pimpl_->m_condVar_account_removal.notify_all(); + accountInfo->second.enabled = enabled; } bool @@ -147,7 +188,21 @@ NewAccountModel::changeAccountPassword(const std::string& accountId, const std::string& newPassword) const { return ConfigurationManager::instance() - .changeAccountPassword(accountId.c_str(), currentPassword.c_str(), newPassword.c_str()); + .changeAccountPassword(accountId.c_str(), currentPassword.c_str(), newPassword.c_str()); +} + +void +NewAccountModel::flagFreeable(const std::string& accountId) const +{ + auto accountInfo = pimpl_->accounts.find(accountId); + if (accountInfo == pimpl_->accounts.end()) + throw std::out_of_range("NewAccountModel::flagFreeable, can't find " + accountId); + + { + std::lock_guard<std::mutex> lock(pimpl_->m_mutex_account_removal); + accountInfo->second.freeable = true; + } + pimpl_->m_condVar_account_removal.notify_all(); } const account::Info& @@ -177,6 +232,7 @@ NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked, addToAccounts(id.toStdString()); connect(&callbacksHandler, &CallbacksHandler::accountStatusChanged, this, &NewAccountModelPimpl::slotAccountStatusChanged); + connect(&callbacksHandler, &CallbacksHandler::accountDetailsChanged, this, &NewAccountModelPimpl::slotAccountDetailsChanged); // NOTE: because we still use the legacy LRC for configuration, we are still using old signals connect(&AccountModel::instance(), &AccountModel::accountRemoved, this, &NewAccountModelPimpl::slotAccountRemoved); @@ -213,27 +269,34 @@ NewAccountModelPimpl::slotAccountStatusChanged(const std::string& accountID, con } void -NewAccountModelPimpl::addToAccounts(const std::string& accountId) +NewAccountModelPimpl::slotAccountDetailsChanged(const std::string& accountId, const std::map<std::string, std::string>& details) { - QMap<QString, QString> details = ConfigurationManager::instance().getAccountDetails(accountId.c_str()); - const MapStringString volatileDetails = ConfigurationManager::instance().getVolatileAccountDetails(accountId.c_str()); + auto accountInfo = accounts.find(accountId); + if (accountInfo == accounts.end()) { + throw std::out_of_range("NewAccountModelPimpl::slotAccountDetailsChanged, can't find " + accountId); + } + + accountInfo->second.fromDetails(convertMap(details)); + emit linked.accountStatusChanged(accountId); +} +void +NewAccountModelPimpl::addToAccounts(const std::string& accountId) +{ // Init profile auto& item = *(accounts.emplace(accountId, account::Info()).first); auto& owner = item.second; owner.id = accountId; - owner.enabled = details["Account.enable"] == QString("true"); - owner.profileInfo.type = details["Account.type"] == "RING" ? profile::Type::RING : profile::Type::SIP; - owner.profileInfo.alias = details["Account.alias"].toStdString(); - owner.registeredName = owner.profileInfo.type == profile::Type::RING ? - volatileDetails["Account.registredName"].toStdString() : owner.profileInfo.alias; - owner.profileInfo.uri = (owner.profileInfo.type == profile::Type::RING and details["Account.username"].contains("ring:")) ? - details["Account.username"].toStdString().substr(std::string("ring:").size()) - : details["Account.username"].toStdString(); + // Fill account::Info struct with details from daemon + MapStringString details = ConfigurationManager::instance().getAccountDetails(accountId.c_str()); + owner.fromDetails(details); + // Add profile into database + using namespace DRing::Account; + auto accountType = owner.profileInfo.type == profile::Type::RING ? std::string(ProtocolNames::RING) : std::string(ProtocolNames::SIP); auto accountProfileId = authority::database::getOrInsertProfile(database, owner.profileInfo.uri, owner.profileInfo.alias, "", - details["Account.type"].toStdString()); + accountType); // Retrieve avatar from database auto avatar = authority::database::getAvatarForProfileId(database, accountProfileId); owner.profileInfo.avatar = avatar; @@ -271,7 +334,6 @@ NewAccountModelPimpl::slotAccountRemoved(Account* account) accounts.erase(accountId); } - void NewAccountModelPimpl::slotProfileUpdated(const Profile* profile) { @@ -280,6 +342,184 @@ NewAccountModelPimpl::slotProfileUpdated(const Profile* profile) emit linked.profileUpdated(accounts.first()->id().toStdString()); } +void +account::Info::fromDetails(const MapStringString& details) +{ + using namespace DRing::Account; + const MapStringString volatileDetails = ConfigurationManager::instance().getVolatileAccountDetails(id.c_str()); + + // General + if (details[ConfProperties::TYPE] != "") + profileInfo.type = details[ConfProperties::TYPE] == QString(ProtocolNames::RING) ? profile::Type::RING : profile::Type::SIP; + registeredName = profileInfo.type == profile::Type::RING ? volatileDetails[VolatileProperties::REGISTERED_NAME].toStdString() : profileInfo.alias; + profileInfo.alias = toStdString(details[ConfProperties::ALIAS]); + confProperties.displayName = toStdString(details[ConfProperties::DISPLAYNAME]); + enabled = toBool(details[ConfProperties::ENABLED]); + confProperties.mailbox = toStdString(details[ConfProperties::MAILBOX]); + confProperties.dtmfType = toStdString(details[ConfProperties::DTMF_TYPE]); + confProperties.autoAnswer = toBool(details[ConfProperties::AUTOANSWER]); + confProperties.activeCallLimit = toInt(details[ConfProperties::ACTIVE_CALL_LIMIT]); + confProperties.hostname = toStdString(details[ConfProperties::HOSTNAME]); + profileInfo.uri = (profileInfo.type == profile::Type::RING and details[ConfProperties::USERNAME].contains("ring:")) ? details[ConfProperties::USERNAME].toStdString().substr(std::string("ring:").size()) : details[ConfProperties::USERNAME].toStdString(); + confProperties.routeset = toStdString(details[ConfProperties::ROUTE]); + confProperties.password = toStdString(details[ConfProperties::PASSWORD]); + confProperties.realm = toStdString(details[ConfProperties::REALM]); + confProperties.localInterface = toStdString(details[ConfProperties::LOCAL_INTERFACE]); + confProperties.publishedSameAsLocal = toBool(details[ConfProperties::PUBLISHED_SAMEAS_LOCAL]); + confProperties.localPort = toInt(details[ConfProperties::LOCAL_PORT]); + confProperties.publishedPort = toInt(details[ConfProperties::PUBLISHED_PORT]); + confProperties.publishedAddress = toStdString(details[ConfProperties::PUBLISHED_ADDRESS]); + confProperties.userAgent = toStdString(details[ConfProperties::USER_AGENT]); + confProperties.upnpEnabled = toBool(details[ConfProperties::UPNP_ENABLED]); + confProperties.hasCustomUserAgent = toBool(details[ConfProperties::HAS_CUSTOM_USER_AGENT]); + confProperties.allowIncomingFromHistory = toBool(details[ConfProperties::ALLOW_CERT_FROM_HISTORY]); + confProperties.allowIncomingFromContact = toBool(details[ConfProperties::ALLOW_CERT_FROM_CONTACT]); + confProperties.allowIncomingFromTrusted = toBool(details[ConfProperties::ALLOW_CERT_FROM_TRUSTED]); + confProperties.archivePassword = toStdString(details[ConfProperties::ARCHIVE_PASSWORD]); + confProperties.archiveHasPassword = toBool(details[ConfProperties::ARCHIVE_HAS_PASSWORD]); + confProperties.archivePath = toStdString(details[ConfProperties::ARCHIVE_PATH]); + confProperties.archivePin = toStdString(details[ConfProperties::ARCHIVE_PIN]); + confProperties.proxyEnabled = toBool(details[ConfProperties::PROXY_ENABLED]); + confProperties.proxyServer = toStdString(details[ConfProperties::PROXY_SERVER]); + confProperties.proxyPushToken = toStdString(details[ConfProperties::PROXY_PUSH_TOKEN]); + // Audio + confProperties.Audio.audioPortMax = toInt(details[ConfProperties::Audio::PORT_MAX]); + confProperties.Audio.audioPortMin = toInt(details[ConfProperties::Audio::PORT_MIN]); + // Video + confProperties.Video.videoEnabled = toBool(details[ConfProperties::Video::ENABLED]); + confProperties.Video.videoPortMax = toInt(details[ConfProperties::Video::PORT_MAX]); + confProperties.Video.videoPortMin = toInt(details[ConfProperties::Video::PORT_MIN]); + // STUN + confProperties.STUN.server = toStdString(details[ConfProperties::STUN::SERVER]); + confProperties.STUN.enable = toBool(details[ConfProperties::STUN::ENABLED]); + // TURN + confProperties.TURN.server = toStdString(details[ConfProperties::TURN::SERVER]); + confProperties.TURN.enable = toBool(details[ConfProperties::TURN::ENABLED]); + confProperties.TURN.username = toStdString(details[ConfProperties::TURN::SERVER_UNAME]); + confProperties.TURN.password = toStdString(details[ConfProperties::TURN::SERVER_PWD]); + confProperties.TURN.realm = toStdString(details[ConfProperties::TURN::SERVER_REALM]); + // Presence + confProperties.Presence.presencePublishSupported = toBool(details[ConfProperties::Presence::SUPPORT_PUBLISH]); + confProperties.Presence.presenceSubscribeSupported = toBool(details[ConfProperties::Presence::SUPPORT_SUBSCRIBE]); + confProperties.Presence.presenceEnabled = toBool(details[ConfProperties::Presence::ENABLED]); + // Ringtone + confProperties.Ringtone.ringtonePath = toStdString(details[ConfProperties::Ringtone::PATH]); + confProperties.Ringtone.ringtoneEnabled = toBool(details[ConfProperties::Ringtone::ENABLED]); + // SRTP + confProperties.SRTP.keyExchange = toStdString(details[ConfProperties::SRTP::KEY_EXCHANGE]); + confProperties.SRTP.enable = toBool(details[ConfProperties::SRTP::ENABLED]); + confProperties.SRTP.rtpFallback = toBool(details[ConfProperties::SRTP::RTP_FALLBACK]); + // TLS + confProperties.TLS.listenerPort = toInt(details[ConfProperties::TLS::LISTENER_PORT]); + confProperties.TLS.enable = toBool(details[ConfProperties::TLS::ENABLED]); + confProperties.TLS.port = toInt(details[ConfProperties::TLS::PORT]); + confProperties.TLS.certificateListFile = toStdString(details[ConfProperties::TLS::CA_LIST_FILE]); + confProperties.TLS.certificateFile = toStdString(details[ConfProperties::TLS::CERTIFICATE_FILE]); + confProperties.TLS.privateKeyFile = toStdString(details[ConfProperties::TLS::PRIVATE_KEY_FILE]); + confProperties.TLS.password = toStdString(details[ConfProperties::TLS::PASSWORD]); + confProperties.TLS.method = toStdString(details[ConfProperties::TLS::METHOD]); + confProperties.TLS.ciphers = toStdString(details[ConfProperties::TLS::CIPHERS]); + confProperties.TLS.serverName = toStdString(details[ConfProperties::TLS::SERVER_NAME]); + confProperties.TLS.verifyServer = toBool(details[ConfProperties::TLS::VERIFY_SERVER]); + confProperties.TLS.verifyClient = toBool(details[ConfProperties::TLS::VERIFY_CLIENT]); + confProperties.TLS.requireClientCertificate = toBool(details[ConfProperties::TLS::REQUIRE_CLIENT_CERTIFICATE]); + confProperties.TLS.negotiationTimeoutSec = toInt(details[ConfProperties::TLS::NEGOTIATION_TIMEOUT_SEC]); + // DHT + confProperties.DHT.port = toInt(details[ConfProperties::DHT::PORT]); + confProperties.DHT.PublicInCalls = toBool(details[ConfProperties::DHT::PUBLIC_IN_CALLS]); + confProperties.DHT.AllowFromTrusted = toBool(details[ConfProperties::DHT::ALLOW_FROM_TRUSTED]); + // RingNS + confProperties.RingNS.uri = toStdString(details[ConfProperties::RingNS::URI]); + confProperties.RingNS.account = toStdString(details[ConfProperties::RingNS::ACCOUNT]); +} + +MapStringString +account::ConfProperties_t::toDetails() const +{ + using namespace DRing::Account; + MapStringString details; + // General + details[ConfProperties::DISPLAYNAME] = toQString(this->displayName); + details[ConfProperties::MAILBOX] = toQString(this->mailbox); + details[ConfProperties::DTMF_TYPE] = toQString(this->dtmfType); + details[ConfProperties::AUTOANSWER] = toQString(this->autoAnswer); + details[ConfProperties::ACTIVE_CALL_LIMIT] = toQString(this->activeCallLimit); + details[ConfProperties::HOSTNAME] = toQString(this->hostname); + details[ConfProperties::ROUTE] = toQString(this->routeset); + details[ConfProperties::PASSWORD] = toQString(this->password); + details[ConfProperties::REALM] = toQString(this->realm); + details[ConfProperties::LOCAL_INTERFACE] = toQString(this->localInterface); + details[ConfProperties::PUBLISHED_SAMEAS_LOCAL] = toQString(this->publishedSameAsLocal); + details[ConfProperties::LOCAL_PORT] = toQString(this->localPort); + details[ConfProperties::PUBLISHED_PORT] = toQString(this->publishedPort); + details[ConfProperties::PUBLISHED_ADDRESS] = toQString(this->publishedAddress); + details[ConfProperties::USER_AGENT] = toQString(this->userAgent); + details[ConfProperties::UPNP_ENABLED] = toQString(this->upnpEnabled); + details[ConfProperties::HAS_CUSTOM_USER_AGENT] = toQString(this->hasCustomUserAgent); + details[ConfProperties::ALLOW_CERT_FROM_HISTORY] = toQString(this->allowIncomingFromHistory); + details[ConfProperties::ALLOW_CERT_FROM_CONTACT] = toQString(this->allowIncomingFromContact); + details[ConfProperties::ALLOW_CERT_FROM_TRUSTED] = toQString(this->allowIncomingFromTrusted); + details[ConfProperties::ARCHIVE_PASSWORD] = toQString(this->archivePassword); + details[ConfProperties::ARCHIVE_HAS_PASSWORD] = toQString(this->archiveHasPassword); + details[ConfProperties::ARCHIVE_PATH] = toQString(this->archivePath); + details[ConfProperties::ARCHIVE_PIN] = toQString(this->archivePin); + // ConfProperties::DEVICE_NAME name is set with NewDeviceModel interface + details[ConfProperties::PROXY_ENABLED] = toQString(this->proxyEnabled); + details[ConfProperties::PROXY_SERVER] = toQString(this->proxyServer); + details[ConfProperties::PROXY_PUSH_TOKEN] = toQString(this->proxyPushToken); + // Audio + details[ConfProperties::Audio::PORT_MAX] = toQString(this->Audio.audioPortMax); + details[ConfProperties::Audio::PORT_MIN] = toQString(this->Audio.audioPortMin); + // Video + details[ConfProperties::Video::ENABLED] = toQString(this->Video.videoEnabled); + details[ConfProperties::Video::PORT_MAX] = toQString(this->Video.videoPortMax); + details[ConfProperties::Video::PORT_MIN] = toQString(this->Video.videoPortMin); + // STUN + details[ConfProperties::STUN::SERVER] = toQString(this->STUN.server); + details[ConfProperties::STUN::ENABLED] = toQString(this->STUN.enable); + // TURN + details[ConfProperties::TURN::SERVER] = toQString(this->TURN.server); + details[ConfProperties::TURN::ENABLED] = toQString(this->TURN.enable); + details[ConfProperties::TURN::SERVER_UNAME] = toQString(this->TURN.username); + details[ConfProperties::TURN::SERVER_PWD] = toQString(this->TURN.password); + details[ConfProperties::TURN::SERVER_REALM] = toQString(this->TURN.realm); + // Presence + details[ConfProperties::Presence::SUPPORT_PUBLISH] = toQString(this->Presence.presencePublishSupported); + details[ConfProperties::Presence::SUPPORT_SUBSCRIBE] = toQString(this->Presence.presenceSubscribeSupported); + details[ConfProperties::Presence::ENABLED] = toQString(this->Presence.presenceEnabled); + // Ringtone + details[ConfProperties::Ringtone::PATH] = toQString(this->Ringtone.ringtonePath); + details[ConfProperties::Ringtone::ENABLED] = toQString(this->Ringtone.ringtoneEnabled); + // SRTP + details[ConfProperties::SRTP::KEY_EXCHANGE] = toQString(this->SRTP.keyExchange); + details[ConfProperties::SRTP::ENABLED] = toQString(this->SRTP.enable); + details[ConfProperties::SRTP::RTP_FALLBACK] = toQString(this->SRTP.rtpFallback); + // TLS + details[ConfProperties::TLS::LISTENER_PORT] = toQString(this->TLS.listenerPort); + details[ConfProperties::TLS::ENABLED] = toQString(this->TLS.enable); + details[ConfProperties::TLS::PORT] = toQString(this->TLS.port); + details[ConfProperties::TLS::CA_LIST_FILE] = toQString(this->TLS.certificateListFile); + details[ConfProperties::TLS::CERTIFICATE_FILE] = toQString(this->TLS.certificateFile); + details[ConfProperties::TLS::PRIVATE_KEY_FILE] = toQString(this->TLS.privateKeyFile); + details[ConfProperties::TLS::PASSWORD] = toQString(this->TLS.password); + details[ConfProperties::TLS::METHOD] = toQString(this->TLS.method); + details[ConfProperties::TLS::CIPHERS] = toQString(this->TLS.ciphers); + details[ConfProperties::TLS::SERVER_NAME] = toQString(this->TLS.serverName); + details[ConfProperties::TLS::VERIFY_SERVER] = toQString(this->TLS.verifyServer); + details[ConfProperties::TLS::VERIFY_CLIENT] = toQString(this->TLS.verifyClient); + details[ConfProperties::TLS::REQUIRE_CLIENT_CERTIFICATE] = toQString(this->TLS.requireClientCertificate); + details[ConfProperties::TLS::NEGOTIATION_TIMEOUT_SEC] = toQString(this->TLS.negotiationTimeoutSec); + // DHT + details[ConfProperties::DHT::PORT] = toQString(this->DHT.port); + details[ConfProperties::DHT::PUBLIC_IN_CALLS] = toQString(this->DHT.PublicInCalls); + details[ConfProperties::DHT::ALLOW_FROM_TRUSTED] = toQString(this->DHT.AllowFromTrusted); + // RingNS + details[ConfProperties::RingNS::URI] = toQString(this->RingNS.uri); + details[ConfProperties::RingNS::ACCOUNT] = toQString(this->RingNS.account); + + return details; +} + } // namespace lrc #include "api/moc_newaccountmodel.cpp" diff --git a/src/qtwrapper/configurationmanager_wrap.h b/src/qtwrapper/configurationmanager_wrap.h index 3d4e0ca6c6abbf4506921810358f9627dd357491..0279ba6fcaa2939c8cd7fd135b41819354cc0042 100644 --- a/src/qtwrapper/configurationmanager_wrap.h +++ b/src/qtwrapper/configurationmanager_wrap.h @@ -64,6 +64,12 @@ public: [this] () { Q_EMIT this->accountsChanged(); }), + exportable_callback<ConfigurationSignal::AccountDetailsChanged>( + [this] (const std::string& account_id, + const std::map<std::string, std::string>& details) { + Q_EMIT this->accountDetailsChanged(QString(account_id.c_str()), + convertMap(details)); + }), exportable_callback<ConfigurationSignal::StunStatusFailed>( [this] (const std::string &reason) { Q_EMIT this->stunStatusFailure(QString(reason.c_str())); @@ -657,6 +663,7 @@ public Q_SLOTS: // METHODS Q_SIGNALS: // SIGNALS void volumeChanged(const QString& device, double value); void accountsChanged(); + void accountDetailsChanged(const QString& accountId, const MapStringString& details); void historyChanged(); void stunStatusFailure(const QString& reason); void registrationStateChanged(const QString& accountID, const QString& registration_state, unsigned detail_code, const QString& detail_str); diff --git a/src/qtwrapper/conversions_wrap.hpp b/src/qtwrapper/conversions_wrap.hpp index f20030423e5a6edc17c653302c7f29251a00c3d6..1fc63e178a7ce271bf4610ff4270a1985bec817e 100644 --- a/src/qtwrapper/conversions_wrap.hpp +++ b/src/qtwrapper/conversions_wrap.hpp @@ -103,4 +103,43 @@ inline MapStringInt convertStringInt(const std::map<std::string, int>& m) { return temp; } +constexpr static const char* TRUE_STR = "true"; +constexpr static const char* FALSE_STR = "false"; + +static inline QString +toQString(bool b) noexcept +{ + return b ? TRUE_STR : FALSE_STR; +} + +static inline QString +toQString(const std::string& str) noexcept +{ + return QString::fromStdString(str); +} + +static inline QString +toQString(int i) noexcept +{ + return QString::number(i); +} + +static inline bool +toBool(QString qs) noexcept +{ + return qs == TRUE_STR ? true : false; +} + +static inline int +toInt(QString qs) noexcept +{ + return qs.toInt(); +} + +static inline std::string +toStdString(QString qs) noexcept +{ + return qs.toStdString(); +} + #endif //CONVERSIONS_WRAP_H diff --git a/test/mocks/configurationmanager_mock.h b/test/mocks/configurationmanager_mock.h index 90ce44b852beeceb70ed58411e64760e85544631..740469ec98c5cd05adefa8eb03a5740d1e0f638e 100644 --- a/test/mocks/configurationmanager_mock.h +++ b/test/mocks/configurationmanager_mock.h @@ -812,32 +812,33 @@ public Q_SLOTS: // METHODS void stopProxyClient(const std::string& /*accountID*/) { } Q_SIGNALS: // SIGNALS - void volumeChanged(const QString& device, double value); - void accountsChanged(); - void historyChanged(); - void stunStatusFailure(const QString& reason); - void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str); - void stunStatusSuccess(const QString& message); - void errorAlert(int code); - void volatileAccountDetailsChanged(const QString& accountId, MapStringString details); - void certificatePinned(const QString& certId); - void certificatePathPinned(const QString& path, const QStringList& certIds); - void certificateExpired(const QString& certId); - void certificateStateChanged(const QString& accountId, const QString& certId, const QString& status); - void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp); - void knownDevicesChanged(const QString& accountId, const MapStringString& devices); - void exportOnRingEnded(const QString& accountId, int status, const QString& pin); - void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads); - void mediaParametersChanged(const QString& accountId); - void audioDeviceEvent(); - void accountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status); - void nameRegistrationEnded(const QString& accountId, int status, const QString& name); - void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name); // used by conversationModel - void migrationEnded(const QString &accountId, const QString &result); - void contactAdded(const QString &accountId, const QString &uri, bool banned); - void contactRemoved(const QString &accountId, const QString &uri, bool banned); - void dataTransferEvent(uint64_t transfer_id, uint32_t code); - void deviceRevocationEnded(const QString& accountId, const QString& deviceId, int status); + void volumeChanged(const QString& device, double value); + void accountsChanged(); + void accountDetailsChanged(const QString& accountId, const MapStringString& details); + void historyChanged(); + void stunStatusFailure(const QString& reason); + void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str); + void stunStatusSuccess(const QString& message); + void errorAlert(int code); + void volatileAccountDetailsChanged(const QString& accountId, MapStringString details); + void certificatePinned(const QString& certId); + void certificatePathPinned(const QString& path, const QStringList& certIds); + void certificateExpired(const QString& certId); + void certificateStateChanged(const QString& accountId, const QString& certId, const QString& status); + void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp); + void knownDevicesChanged(const QString& accountId, const MapStringString& devices); + void exportOnRingEnded(const QString& accountId, int status, const QString& pin); + void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads); + void mediaParametersChanged(const QString& accountId); + void audioDeviceEvent(); + void accountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status); + void nameRegistrationEnded(const QString& accountId, int status, const QString& name); + void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name); // used by conversationModel + void migrationEnded(const QString &accountId, const QString &result); + void contactAdded(const QString &accountId, const QString &uri, bool banned); + void contactRemoved(const QString &accountId, const QString &uri, bool banned); + void dataTransferEvent(uint64_t transfer_id, uint32_t code); + void deviceRevocationEnded(const QString& accountId, const QString& deviceId, int status); }; namespace org {