diff --git a/src/account.cpp b/src/account.cpp index 03bf1b4bafcb5bced2ffbbb9e7259c9066f7d3cf..f97bd42504094f011d893606668baf7c6e81bb49 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -70,7 +70,8 @@ m_pVideoCodecs(nullptr),m_LastErrorCode(-1),m_VoiceMailCount(0),m_pRingToneModel m_CurrentState(Account::EditState::READY), m_pAccountNumber(nullptr),m_pKeyExchangeModel(nullptr),m_pSecurityValidationModel(nullptr),m_pTlsMethodModel(nullptr), m_pCaCert(nullptr),m_pTlsCert(nullptr),m_pPrivateKey(nullptr),m_isLoaded(true),m_pCipherModel(nullptr), -m_pStatusModel(nullptr),m_LastTransportCode(0),m_RegistrationState(Account::RegistrationState::UNREGISTERED) +m_pStatusModel(nullptr),m_LastTransportCode(0),m_RegistrationState(Account::RegistrationState::UNREGISTERED), +m_UseDefaultPort(false) { Q_Q(Account); } @@ -534,9 +535,9 @@ QString Account::tlsPassword() const } ///Return the account TLS port -int Account::tlsListenerPort() const +int Account::bootstrapPort() const { - return d_ptr->accountDetail(DRing::Account::ConfProperties::TLS::LISTENER_PORT).toInt(); + return d_ptr->accountDetail(DRing::Account::ConfProperties::DHT::PORT).toInt(); } ///Return the account TLS certificate authority list file @@ -659,7 +660,19 @@ QString Account::lastTransportErrorMessage() const ///Return the account local port int Account::localPort() const { - return d_ptr->accountDetail(DRing::Account::ConfProperties::LOCAL_PORT).toInt(); + switch (protocol()) { + case Account::Protocol::SIP: + case Account::Protocol::IAX: + if (isTlsEnabled()) + return d_ptr->accountDetail(DRing::Account::ConfProperties::TLS::LISTENER_PORT).toInt(); + else + return d_ptr->accountDetail(DRing::Account::ConfProperties::LOCAL_PORT).toInt(); + case Account::Protocol::DHT: + return d_ptr->accountDetail(DRing::Account::ConfProperties::TLS::LISTENER_PORT).toInt(); + case Account::Protocol::COUNT__: + break; + }; + return 0; } ///Return the number of voicemails @@ -684,10 +697,12 @@ Account::RegistrationState Account::registrationState() const Account::Protocol Account::protocol() const { const QString str = d_ptr->accountDetail(DRing::Account::ConfProperties::TYPE); - if (str.isEmpty() || str == Account::ProtocolName::SIP) + if (str.isEmpty() || str == DRing::Account::ProtocolNames::SIP) return Account::Protocol::SIP; - else if (str == Account::ProtocolName::IAX) + else if (str == DRing::Account::ProtocolNames::IAX) return Account::Protocol::IAX; + else if (str == DRing::Account::ProtocolNames::DHT) + return Account::Protocol::DHT; qDebug() << "Warning: unhandled protocol name" << str << ", defaulting to SIP"; return Account::Protocol::SIP; } @@ -754,6 +769,11 @@ QString Account::userAgent() const return d_ptr->accountDetail(DRing::Account::ConfProperties::USER_AGENT); } +bool Account::useDefaultPort() const +{ + return d_ptr->m_UseDefaultPort; +} + #define CAST(item) static_cast<int>(item) QVariant Account::roleData(int role) const { @@ -808,8 +828,8 @@ QVariant Account::roleData(int role) const return tlsNegotiationTimeoutSec(); case CAST(Account::Role::LocalPort): return localPort(); - case CAST(Account::Role::TlsListenerPort): - return tlsListenerPort(); + case CAST(Account::Role::BootstrapPort): + return bootstrapPort(); case CAST(Account::Role::PublishedPort): return publishedPort(); case CAST(Account::Role::Enabled): @@ -918,13 +938,13 @@ void Account::setProtocol(Account::Protocol proto) //TODO prevent this if the protocol has been saved switch (proto) { case Account::Protocol::SIP: - d_ptr->setAccountProperty(DRing::Account::ConfProperties::TYPE ,Account::ProtocolName::SIP); + d_ptr->setAccountProperty(DRing::Account::ConfProperties::TYPE ,DRing::Account::ProtocolNames::SIP); break; case Account::Protocol::IAX: - d_ptr->setAccountProperty(DRing::Account::ConfProperties::TYPE ,Account::ProtocolName::IAX); + d_ptr->setAccountProperty(DRing::Account::ConfProperties::TYPE ,DRing::Account::ProtocolNames::IAX); break; case Account::Protocol::DHT: - d_ptr->setAccountProperty(DRing::Account::ConfProperties::TYPE ,Account::ProtocolName::DHT); + d_ptr->setAccountProperty(DRing::Account::ConfProperties::TYPE ,DRing::Account::ProtocolNames::DHT); break; case Account::Protocol::COUNT__: break; @@ -1076,13 +1096,24 @@ void Account::setTlsNegotiationTimeoutSec(int detail) ///Set the local port for SIP/IAX communications void Account::setLocalPort(unsigned short detail) { - d_ptr->setAccountProperty(DRing::Account::ConfProperties::LOCAL_PORT, QString::number(detail)); + switch (protocol()) { + case Account::Protocol::SIP: + case Account::Protocol::IAX: + if (isTlsEnabled()) + d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::LISTENER_PORT, QString::number(detail)); + else + d_ptr->setAccountProperty(DRing::Account::ConfProperties::LOCAL_PORT, QString::number(detail)); + case Account::Protocol::DHT: + d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::LISTENER_PORT, QString::number(detail)); + case Account::Protocol::COUNT__: + break; + }; } ///Set the TLS listener port (0-2^16) -void Account::setTlsListenerPort(unsigned short detail) +void Account::setBootstrapPort(unsigned short detail) { - d_ptr->setAccountProperty(DRing::Account::ConfProperties::TLS::LISTENER_PORT, QString::number(detail)); + d_ptr->setAccountProperty(DRing::Account::ConfProperties::DHT::PORT, QString::number(detail)); } ///Set the published port (0-2^16) @@ -1241,6 +1272,24 @@ void Account::setUserAgent(const QString& agent) d_ptr->setAccountProperty(DRing::Account::ConfProperties::USER_AGENT, agent); } +void Account::setUseDefaultPort(bool value) +{ + if (value) { + switch (protocol()) { + case Account::Protocol::SIP: + case Account::Protocol::IAX: + setLocalPort(5060); + break; + case Account::Protocol::DHT: + setLocalPort(5061); + break; + case Account::Protocol::COUNT__: + break; + }; + } + d_ptr->m_UseDefaultPort = value; +} + ///Set the DTMF type void Account::setDTMFType(DtmfType type) { @@ -1325,8 +1374,8 @@ void Account::setRoleData(int role, const QVariant& value) case CAST(Account::Role::LocalPort): setLocalPort(value.toInt()); break; - case CAST(Account::Role::TlsListenerPort): - setTlsListenerPort(value.toInt()); + case CAST(Account::Role::BootstrapPort): + setBootstrapPort(value.toInt()); break; case CAST(Account::Role::PublishedPort): setPublishedPort(value.toInt()); diff --git a/src/account.h b/src/account.h index f7e97dcdbb3c14da3b03234a509e4a152629bd64..7f21fc3cbf94bd0f33b4ec0c5fefe832bdd2be0d 100644 --- a/src/account.h +++ b/src/account.h @@ -97,7 +97,7 @@ class LIB_EXPORT Account : public QObject { Q_PROPERTY(int registrationExpire READ registrationExpire WRITE setRegistrationExpire ) Q_PROPERTY(int tlsNegotiationTimeoutSec READ tlsNegotiationTimeoutSec WRITE setTlsNegotiationTimeoutSec ) Q_PROPERTY(int localPort READ localPort WRITE setLocalPort ) - Q_PROPERTY(int tlsListenerPort READ tlsListenerPort WRITE setTlsListenerPort ) + Q_PROPERTY(int bootstrapPort READ bootstrapPort WRITE setBootstrapPort ) Q_PROPERTY(int publishedPort READ publishedPort WRITE setPublishedPort ) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled ) Q_PROPERTY(bool autoAnswer READ isAutoAnswer WRITE setAutoAnswer ) @@ -127,6 +127,7 @@ class LIB_EXPORT Account : public QObject { Q_PROPERTY(int audioPortMax READ audioPortMax WRITE setAudioPortMax ) Q_PROPERTY(int audioPortMin READ audioPortMin WRITE setAudioPortMin ) Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent ) + Q_PROPERTY(bool useDefaultPort READ useDefaultPort WRITE setUseDefaultPort ) Q_PROPERTY(RegistrationState registrationState READ registrationState ) public: @@ -182,7 +183,7 @@ class LIB_EXPORT Account : public QObject { TlsNegotiationTimeoutSec = 119, TlsNegotiationTimeoutMsec = 120, LocalPort = 121, - TlsListenerPort = 122, + BootstrapPort = 122, PublishedPort = 123, Enabled = 124, AutoAnswer = 125, @@ -205,14 +206,7 @@ class LIB_EXPORT Account : public QObject { PresenceStatus = 142, PresenceMessage = 143, RegistrationState = 144, - }; - - class ProtocolName { - public: - constexpr static const char* SIP = "SIP" ; - constexpr static const char* IAX = "IAX" ; - constexpr static const char* IP2IP = "IP2IP"; - constexpr static const char* DHT = "DHT" ; + UseDefaultPort = 145, }; enum class Protocol { @@ -271,7 +265,7 @@ class LIB_EXPORT Account : public QObject { QString publishedAddress () const; int publishedPort () const; QString tlsPassword () const; - int tlsListenerPort () const; + int bootstrapPort () const; Certificate* tlsCaListCertificate () const; Certificate* tlsCertificate () const; Certificate* tlsPrivateKeyCertificate() const; @@ -302,6 +296,7 @@ class LIB_EXPORT Account : public QObject { int lastTransportErrorCode () const; QString lastTransportErrorMessage () const; QString userAgent () const; + bool useDefaultPort () const; RegistrationState registrationState () const; Account::Protocol protocol () const; KeyExchangeModel::Type keyExchange () const; @@ -332,7 +327,7 @@ class LIB_EXPORT Account : public QObject { void setRegistrationExpire (int detail); void setTlsNegotiationTimeoutSec (int detail); void setLocalPort (unsigned short detail); - void setTlsListenerPort (unsigned short detail); + void setBootstrapPort (unsigned short detail); void setPublishedPort (unsigned short detail); void setAutoAnswer (bool detail); void setTlsVerifyServer (bool detail); @@ -356,6 +351,7 @@ class LIB_EXPORT Account : public QObject { void setVideoPortMin (int port ); void setDTMFType (DtmfType type); void setUserAgent (const QString& agent); + void setUseDefaultPort (bool value ); void setRoleData(int role, const QVariant& value); diff --git a/src/accountmodel.cpp b/src/accountmodel.cpp index 863121f40225a2364f8191b86f6ae5e315274ba6..f6e8ad43e914100dc3c64987bf2ddc6e590679a5 100644 --- a/src/accountmodel.cpp +++ b/src/accountmodel.cpp @@ -111,7 +111,7 @@ QHash<int,QByteArray> AccountModel::roleNames() const roles.insert(CAST(Account::Role::TlsNegotiationTimeoutSec ) ,QByteArray("tlsNegotiationTimeoutSec" )); roles.insert(CAST(Account::Role::TlsNegotiationTimeoutMsec ) ,QByteArray("tlsNegotiationTimeoutMsec" )); roles.insert(CAST(Account::Role::LocalPort ) ,QByteArray("localPort" )); - roles.insert(CAST(Account::Role::TlsListenerPort ) ,QByteArray("tlsListenerPort" )); + roles.insert(CAST(Account::Role::BootstrapPort ) ,QByteArray("bootstrapPort" )); roles.insert(CAST(Account::Role::PublishedPort ) ,QByteArray("publishedPort" )); roles.insert(CAST(Account::Role::Enabled ) ,QByteArray("enabled" )); roles.insert(CAST(Account::Role::AutoAnswer ) ,QByteArray("autoAnswer" )); @@ -143,7 +143,7 @@ Account* AccountModel::ip2ip() const { if (!d_ptr->m_pIP2IP) { foreach(Account* a, d_ptr->m_lAccounts) { - if (a->id() == Account::ProtocolName::IP2IP) + if (a->id() == DRing::Account::ProtocolNames::IP2IP) d_ptr->m_pIP2IP = a; } } @@ -177,6 +177,7 @@ Account::RegistrationState AccountModelPrivate::fromDaemonName(const QString& st return Account::RegistrationState::TRYING; else if( st == DRing::Account::States::ERROR + || st == DRing::Account::States::ERROR_GENERIC || st == DRing::Account::States::ERROR_AUTH || st == DRing::Account::States::ERROR_NETWORK || st == DRing::Account::States::ERROR_HOST diff --git a/src/availableaccountmodel.cpp b/src/availableaccountmodel.cpp index f528d3e4e24ea0750a6ca922764d0d55adb8fb70..4b59206c6739ba811cf9a1602d29dd01e906cee4 100644 --- a/src/availableaccountmodel.cpp +++ b/src/availableaccountmodel.cpp @@ -21,6 +21,9 @@ #include <QtCore/QItemSelectionModel> #include <QtCore/QCoreApplication> +//DRing +#include <account_const.h> + //Ring #include "private/accountmodel_p.h" @@ -100,7 +103,7 @@ Account* AvailableAccountModel::currentDefaultAccount() else { Account* a = AvailableAccountModelPrivate::firstRegisteredAccount(); if (!a) - a = AccountModel::instance()->getById(Account::ProtocolName::IP2IP); + a = AccountModel::instance()->getById(DRing::Account::ProtocolNames::IP2IP); AvailableAccountModelPrivate::setPriorAccount(a); return a; diff --git a/src/call.cpp b/src/call.cpp index 4117f6b6ba8c97e6c280570192bae07a4d2f869e..6ab460dcfa66ee7093839f4257d6058bea5bdb3c 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -27,6 +27,8 @@ #include <QtCore/QFile> #include <QtCore/QTimer> +//DRing +#include <account_const.h> //Ring library #include "dbus/callmanager.h" @@ -406,7 +408,7 @@ Call* Call::buildHistoryCall(const QMap<QString,QString>& hc) if (accId.isEmpty()) { qWarning() << "An history call has an invalid account identifier"; - accId = Account::ProtocolName::IP2IP; + accId = DRing::Account::ProtocolNames::IP2IP; } //Try to assiciate a contact now, the real contact object is probably not diff --git a/src/ciphermodel.cpp b/src/ciphermodel.cpp index 5f531414adc80611149bab847ccce078dba63f51..ff130eaca264c5035c21e98b70f55b6426e2f42d 100644 --- a/src/ciphermodel.cpp +++ b/src/ciphermodel.cpp @@ -50,7 +50,7 @@ QHash<QString,int> CipherModelPrivate::m_shMapping; CipherModelPrivate::CipherModelPrivate(Account* parent) : m_pAccount(parent) { if (!CipherModelPrivate::m_sIsLoaded) { - const QStringList cs = DBus::ConfigurationManager::instance().getSupportedCiphers(Account::ProtocolName::IP2IP); + const QStringList cs = DBus::ConfigurationManager::instance().getSupportedCiphers(DRing::Account::ProtocolNames::IP2IP); foreach(const QString& c, cs) m_slSupportedCiphers << c.toLatin1(); m_sIsLoaded = true; diff --git a/src/numbercompletionmodel.cpp b/src/numbercompletionmodel.cpp index 27c540d03d829f832927271d3798aa5180401dfc..e3a75d220a813c005e09b893c25c8442890a2d6a 100644 --- a/src/numbercompletionmodel.cpp +++ b/src/numbercompletionmodel.cpp @@ -23,6 +23,9 @@ //System #include <cmath> +//DRing +#include <account_const.h> + //Ring #include "phonedirectorymodel.h" #include "contactmethod.h" @@ -108,7 +111,7 @@ QVariant NumberCompletionModel::data(const QModelIndex& index, int role ) const const int weight = i.key (); bool needAcc = (role>=100 || role == Qt::UserRole) && n->account() && n->account() != AvailableAccountModel::currentDefaultAccount() - && n->account()->alias() != Account::ProtocolName::IP2IP; + && n->account()->alias() != DRing::Account::ProtocolNames::IP2IP; switch (static_cast<NumberCompletionModelPrivate::Columns>(index.column())) { case NumberCompletionModelPrivate::Columns::CONTENT: diff --git a/src/phonedirectorymodel.cpp b/src/phonedirectorymodel.cpp index 8830de8849a14e8dda004b3f307f260750cdce62..9cedf205f6aaac4f006457104e404740185eb780 100644 --- a/src/phonedirectorymodel.cpp +++ b/src/phonedirectorymodel.cpp @@ -20,6 +20,9 @@ //Qt #include <QtCore/QCoreApplication> +//DRing +#include <account_const.h> + //Ring #include "contactmethod.h" #include "call.h" @@ -374,7 +377,7 @@ ContactMethod* PhoneDirectoryModelPrivate::fillDetails(NumberWrapper* wrap, cons /* Has hostname */ strippedUri == number->uri() /* Something with an hostname can be used with IP2IP */ //TODO support DHT here - || (account && account->id() == Account::ProtocolName::IP2IP) + || (account && account->id() == DRing::Account::ProtocolNames::IP2IP) ) : ( /* Has no hostname */ number->account() && number->uri()+'@'+number->account()->hostname() == strippedUri )); @@ -386,7 +389,7 @@ ContactMethod* PhoneDirectoryModelPrivate::fillDetails(NumberWrapper* wrap, cons || (account == number->account()) /* IP2IP is a special case */ //TODO support DHT here || ( - account->id() == Account::ProtocolName::IP2IP + account->id() == DRing::Account::ProtocolNames::IP2IP && strippedUri.hasHostname() )); diff --git a/src/private/account_p.h b/src/private/account_p.h index 60f6c1630826d8f537244dc46a1f593d03d26f38..ddc94a76e3b07fa0acca2ced13a16da52f1810fb 100644 --- a/src/private/account_p.h +++ b/src/private/account_p.h @@ -65,6 +65,7 @@ public: QString m_LastTransportMessage ; Account::RegistrationState m_RegistrationState ; QString m_LastSipRegistrationStatus; + unsigned short m_UseDefaultPort ; //Setters void setAccountProperties(const QHash<QString,QString>& m );