Improve coding style

This commit is contained in:
Vladimir Golovnev (Glassez) 2020-11-16 10:02:11 +03:00 committed by sledgehammer999
parent d3f46452a9
commit 1728c16580
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
147 changed files with 4454 additions and 2227 deletions

View file

@ -56,7 +56,8 @@ DNSUpdater::DNSUpdater(QObject *parent)
// Check lastUpdate to avoid flooding
if (!m_lastIPCheckTime.isValid()
|| (m_lastIPCheckTime.secsTo(QDateTime::currentDateTime()) * 1000 > IP_CHECK_INTERVAL_MS)) {
|| (m_lastIPCheckTime.secsTo(QDateTime::currentDateTime()) * 1000 > IP_CHECK_INTERVAL_MS))
{
checkPublicIP();
}
}
@ -82,30 +83,36 @@ void DNSUpdater::checkPublicIP()
void DNSUpdater::ipRequestFinished(const DownloadResult &result)
{
if (result.status != DownloadStatus::Success) {
if (result.status != DownloadStatus::Success)
{
qWarning() << "IP request failed:" << result.errorString;
return;
}
// Parse response
const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)</body>").match(result.data);
if (ipRegexMatch.hasMatch()) {
if (ipRegexMatch.hasMatch())
{
QString ipStr = ipRegexMatch.captured(1);
qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr;
QHostAddress newIp(ipStr);
if (!newIp.isNull()) {
if (m_lastIP != newIp) {
if (!newIp.isNull())
{
if (m_lastIP != newIp)
{
qDebug() << Q_FUNC_INFO << "The IP address changed, report the change to DynDNS...";
qDebug() << m_lastIP.toString() << "->" << newIp.toString();
m_lastIP = newIp;
updateDNSService();
}
}
else {
else
{
qWarning() << Q_FUNC_INFO << "Failed to construct a QHostAddress from the IP string";
}
}
else {
else
{
qWarning() << Q_FUNC_INFO << "Regular expression failed to capture the IP address";
}
}
@ -133,7 +140,8 @@ QString DNSUpdater::getUpdateUrl() const
Q_ASSERT(!m_lastIP.isNull());
// Service specific
switch (m_service) {
switch (m_service)
{
case DNS::DYNDNS:
url.setHost("members.dyndns.org");
break;
@ -171,12 +179,14 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
const QString code = reply.split(' ').first();
qDebug() << Q_FUNC_INFO << "Code:" << code;
if ((code == "good") || (code == "nochg")) {
if ((code == "good") || (code == "nochg"))
{
logger->addMessage(tr("Your dynamic DNS was successfully updated."), Log::INFO);
return;
}
if ((code == "911") || (code == "dnserr")) {
if ((code == "911") || (code == "dnserr"))
{
logger->addMessage(tr("Dynamic DNS error: The service is temporarily unavailable, it will be retried in 30 minutes."), Log::CRITICAL);
m_lastIP.clear();
// It will retry in 30 minutes because the timer was not stopped
@ -186,33 +196,38 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
// Everything below is an error, stop updating until the user updates something
m_ipCheckTimer.stop();
m_lastIP.clear();
if (code == "nohost") {
if (code == "nohost")
{
logger->addMessage(tr("Dynamic DNS error: hostname supplied does not exist under specified account."), Log::CRITICAL);
m_state = INVALID_CREDS;
return;
}
if (code == "badauth") {
if (code == "badauth")
{
logger->addMessage(tr("Dynamic DNS error: Invalid username/password."), Log::CRITICAL);
m_state = INVALID_CREDS;
return;
}
if (code == "badagent") {
if (code == "badagent")
{
logger->addMessage(tr("Dynamic DNS error: qBittorrent was blacklisted by the service, please report a bug at http://bugs.qbittorrent.org."),
Log::CRITICAL);
m_state = FATAL;
return;
}
if (code == "!donator") {
if (code == "!donator")
{
logger->addMessage(tr("Dynamic DNS error: %1 was returned by the service, please report a bug at http://bugs.qbittorrent.org.").arg("!donator"),
Log::CRITICAL);
m_state = FATAL;
return;
}
if (code == "abuse") {
if (code == "abuse")
{
logger->addMessage(tr("Dynamic DNS error: Your username was blocked due to abuse."), Log::CRITICAL);
m_state = FATAL;
}
@ -225,14 +240,17 @@ void DNSUpdater::updateCredentials()
Logger *const logger = Logger::instance();
bool change = false;
// Get DNS service information
if (m_service != pref->getDynDNSService()) {
if (m_service != pref->getDynDNSService())
{
m_service = pref->getDynDNSService();
change = true;
}
if (m_domain != pref->getDynDomainName()) {
if (m_domain != pref->getDynDomainName())
{
m_domain = pref->getDynDomainName();
const QRegularExpressionMatch domainRegexMatch = QRegularExpression("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$").match(m_domain);
if (!domainRegexMatch.hasMatch()) {
if (!domainRegexMatch.hasMatch())
{
logger->addMessage(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL);
m_lastIP.clear();
m_ipCheckTimer.stop();
@ -241,9 +259,11 @@ void DNSUpdater::updateCredentials()
}
change = true;
}
if (m_username != pref->getDynDNSUsername()) {
if (m_username != pref->getDynDNSUsername())
{
m_username = pref->getDynDNSUsername();
if (m_username.length() < 4) {
if (m_username.length() < 4)
{
logger->addMessage(tr("Dynamic DNS error: supplied username is too short."), Log::CRITICAL);
m_lastIP.clear();
m_ipCheckTimer.stop();
@ -252,9 +272,11 @@ void DNSUpdater::updateCredentials()
}
change = true;
}
if (m_password != pref->getDynDNSPassword()) {
if (m_password != pref->getDynDNSPassword())
{
m_password = pref->getDynDNSPassword();
if (m_password.length() < 4) {
if (m_password.length() < 4)
{
logger->addMessage(tr("Dynamic DNS error: supplied password is too short."), Log::CRITICAL);
m_lastIP.clear();
m_ipCheckTimer.stop();
@ -264,7 +286,8 @@ void DNSUpdater::updateCredentials()
change = true;
}
if ((m_state == INVALID_CREDS) && change) {
if ((m_state == INVALID_CREDS) && change)
{
m_state = OK; // Try again
m_ipCheckTimer.start();
checkPublicIP();
@ -273,7 +296,8 @@ void DNSUpdater::updateCredentials()
QUrl DNSUpdater::getRegistrationUrl(const int service)
{
switch (service) {
switch (service)
{
case DNS::DYNDNS:
return {"https://www.dyndns.com/account/services/hosts/add.html"};
case DNS::NOIP: