From 0d418069762066b4640250efd5ba8d68bf0af178 Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Thu, 16 Jun 2016 15:35:42 -0400 Subject: [PATCH] Sync default port with Use encrypted connection Change the preselected port from 6667 to 6697 when enabling "Use encrypted connection" and change back from 6697 to 6667 when disabling "Use encrypted connection". The port number can be manually changed, stopping the link between checkbox and port. Existing networks are unmodified. Add loosely-standardized default IRC server ports to network.h to provide a central place to manage it. This should only be used when first adding a server. See https://freenode.net/news/port-6697-irc-via-tlsssl --- src/common/network.h | 8 +++++ .../settingspages/networkssettingspage.cpp | 36 +++++++++++++++++++ src/qtui/settingspages/networkssettingspage.h | 20 +++++++++++ 3 files changed, 64 insertions(+) diff --git a/src/common/network.h b/src/common/network.h index 99732d91..bbcd268c 100644 --- a/src/common/network.h +++ b/src/common/network.h @@ -96,6 +96,14 @@ public : D_CHANMODE = 0x08 }; + // Default port assignments according to what many IRC networks have settled on. + // Technically not a standard, but it's fairly widespread. + // See https://freenode.net/news/port-6697-irc-via-tlsssl + enum PortDefaults { + PORT_PLAINTEXT = 6667, /// Default port for unencrypted connections + PORT_SSL = 6697 /// Default port for encrypted connections + }; + struct Server { QString host; uint port; diff --git a/src/qtui/settingspages/networkssettingspage.cpp b/src/qtui/settingspages/networkssettingspage.cpp index cca20e74..7976cca4 100644 --- a/src/qtui/settingspages/networkssettingspage.cpp +++ b/src/qtui/settingspages/networkssettingspage.cpp @@ -786,6 +786,11 @@ NetworkAddDlg::NetworkAddDlg(const QStringList &exist, QWidget *parent) : QDialo ui.setupUi(this); ui.useSSL->setIcon(QIcon::fromTheme("document-encrypt")); + // Whenever useSSL is toggled, update the port number if not changed from the default + connect(ui.useSSL, SIGNAL(toggled(bool)), SLOT(updateSslPort(bool))); + // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden. + // If useSSL is later changed to be checked by default, change port's default value, too. + if (Client::coreFeatures() & Quassel::VerifyServerSSL) { // Synchronize requiring SSL with the use SSL checkbox ui.sslVerify->setEnabled(ui.useSSL->isChecked()); @@ -849,6 +854,19 @@ void NetworkAddDlg::setButtonStates() } +void NetworkAddDlg::updateSslPort(bool isChecked) +{ + // "Use encrypted connection" was toggled, check the state... + if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) { + // Had been using the plain-text port, use the SSL default + ui.port->setValue(Network::PORT_SSL); + } else if (!isChecked && ui.port->value() == Network::PORT_SSL) { + // Had been using the SSL port, use the plain-text default + ui.port->setValue(Network::PORT_PLAINTEXT); + } +} + + /************************************************************************** * NetworkEditDlg *************************************************************************/ @@ -915,6 +933,11 @@ ServerEditDlg::ServerEditDlg(const Network::Server &server, QWidget *parent) : Q ui.sslVersion->hide(); } + // Whenever useSSL is toggled, update the port number if not changed from the default + connect(ui.useSSL, SIGNAL(toggled(bool)), SLOT(updateSslPort(bool))); + // Do NOT call updateSslPort when loading settings, otherwise port settings may be overriden. + // If useSSL is later changed to be checked by default, change port's default value, too. + if (Client::coreFeatures() & Quassel::VerifyServerSSL) { // Synchronize requiring SSL with the use SSL checkbox ui.sslVerify->setEnabled(ui.useSSL->isChecked()); @@ -959,6 +982,19 @@ void ServerEditDlg::on_host_textChanged() } +void ServerEditDlg::updateSslPort(bool isChecked) +{ + // "Use encrypted connection" was toggled, check the state... + if (isChecked && ui.port->value() == Network::PORT_PLAINTEXT) { + // Had been using the plain-text port, use the SSL default + ui.port->setValue(Network::PORT_SSL); + } else if (!isChecked && ui.port->value() == Network::PORT_SSL) { + // Had been using the SSL port, use the plain-text default + ui.port->setValue(Network::PORT_PLAINTEXT); + } +} + + /************************************************************************** * SaveNetworksDlg *************************************************************************/ diff --git a/src/qtui/settingspages/networkssettingspage.h b/src/qtui/settingspages/networkssettingspage.h index 46f0756d..d760621a 100644 --- a/src/qtui/settingspages/networkssettingspage.h +++ b/src/qtui/settingspages/networkssettingspage.h @@ -119,6 +119,16 @@ public: private slots: void setButtonStates(); + /** + * Update the default server port according to isChecked + * + * Connect with useSSL->toggled() in order to keep the port number in sync. This only modifies + * the port if it's not been changed from defaults. + * + * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667. + */ + void updateSslPort(bool isChecked); + private: Ui::NetworkAddDlg ui; @@ -157,6 +167,16 @@ public: private slots: void on_host_textChanged(); + /** + * Update the default server port according to isChecked + * + * Connect with useSSL->toggled() in order to keep the port number in sync. This only modifies + * the port if it's not been changed from defaults. + * + * @param isChecked If true and port unchanged, set port to 6697, else set port to 6667. + */ + void updateSslPort(bool isChecked); + private: Ui::ServerEditDlg ui; }; -- 2.20.1