From ce629c1db1216f2050c2864f244f409836298d25 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 8 Jun 2008 00:14:57 +0200 Subject: [PATCH] Introduce new format for version.inc. This switches from build-number-based versioning to a ProtocolVersion and a version string that is merely descriptive. version.inc can be overriden by version.gen, which is supposed to be generated by build scripts. In addition, we now create a build date automatically. --- src/client/clientsyncer.cpp | 11 +++++----- src/common/CMakeLists.txt | 2 ++ src/common/global.cpp | 33 ++++++++++++++++++++++------ src/common/global.h | 15 ++++++------- src/common/main.cpp | 3 +-- src/core/core.cpp | 43 +++++++++++++++++++++---------------- src/core/ctcphandler.cpp | 4 ++-- src/qtui/aboutdlg.cpp | 2 +- version.inc | 19 +++++----------- 9 files changed, 76 insertions(+), 56 deletions(-) diff --git a/src/client/clientsyncer.cpp b/src/client/clientsyncer.cpp index e7f68b01..93d73bb6 100644 --- a/src/client/clientsyncer.cpp +++ b/src/client/clientsyncer.cpp @@ -157,8 +157,9 @@ void ClientSyncer::coreSocketConnected() { QVariantMap clientInit; clientInit["MsgType"] = "ClientInit"; clientInit["ClientVersion"] = Global::quasselVersion; - clientInit["ClientDate"] = Global::quasselDate; - clientInit["ClientBuild"] = Global::quasselBuild; // this is a minimum, since we probably won't update for every commit + clientInit["ClientBuild"] = 860; // FIXME legacy! + clientInit["ClientDate"] = Global::quasselBuildDate; + clientInit["ProtocolVersion"] = Global::protocolVersion; clientInit["UseSsl"] = coreConnectionInfo["useSsl"]; #ifndef QT_NO_COMPRESS clientInit["UseCompression"] = true; @@ -166,7 +167,6 @@ void ClientSyncer::coreSocketConnected() { clientInit["UseCompression"] = false; #endif - SignalProxy::writeDataToDevice(socket, clientInit); } @@ -186,9 +186,10 @@ void ClientSyncer::coreSocketDisconnected() { void ClientSyncer::clientInitAck(const QVariantMap &msg) { // Core has accepted our version info and sent its own. Let's see if we accept it as well... - if(msg["CoreBuild"].toUInt() < Global::coreBuildNeeded) { + if(msg.contains("CoreBuild") && msg["CoreBuild"].toUInt() < 732 // legacy! + || !msg.contains("CoreBuild") && msg["ProtocolVersion"].toUInt() < Global::clientNeedsProtocol) { emit connectionError(tr("The Quassel Core you are trying to connect to is too old!
" - "Need at least a Core Version %1 (Build >= %2) to connect.").arg(Global::quasselVersion).arg(Global::coreBuildNeeded)); + "Need at least core/client protocol v%1 to connect.").arg(Global::clientNeedsProtocol)); disconnectFromCore(); return; } diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 72e4eb1e..2dcabbe0 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -37,4 +37,6 @@ set(HEADERS qt4_wrap_cpp(MOC ${HEADERS}) +include_directories(${CMAKE_SOURCE_DIR}) # for version.inc and version.gen + add_library(mod_common STATIC ${SOURCES} ${MOC}) diff --git a/src/common/global.cpp b/src/common/global.cpp index 59afde13..a0628862 100644 --- a/src/common/global.cpp +++ b/src/common/global.cpp @@ -98,15 +98,36 @@ void Global::registerMetaTypes() { qRegisterMetaTypeStreamOperators("MsgId"); } +//! This includes version.inc and possibly version.gen and sets up our version numbers. +void Global::setupVersion() { + +# include "version.inc" +# ifdef HAVE_VERSION_GEN +# include "version.gen" +# endif + + if(quasselGeneratedVersion.isEmpty()) { + quasselVersion = QString("v%1 (unknown rev)").arg(quasselBaseVersion); + } else { + QStringList parts = quasselGeneratedVersion.split(':'); + if(parts.count() < 2) parts.append("unknown rev"); + quasselVersion = QString("v%1 (%2)").arg(parts[0], parts[1]); + } +# ifdef __DATE__ + quasselBuildDate = __DATE__; +# endif + +} + // Static variables QString Global::quasselVersion; -QString Global::quasselDate; -uint Global::quasselBuild; -uint Global::clientBuildNeeded; -QString Global::clientVersionNeeded; -uint Global::coreBuildNeeded; -QString Global::coreVersionNeeded; +QString Global::quasselBaseVersion; +QString Global::quasselGeneratedVersion; +QString Global::quasselBuildDate; +uint Global::protocolVersion; +uint Global::clientNeedsProtocol; +uint Global::coreNeedsProtocol; Global::RunMode Global::runMode; uint Global::defaultPort; diff --git a/src/common/global.h b/src/common/global.h index 0759c27e..65d11109 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -33,16 +33,14 @@ namespace Global { extern QString quasselVersion; - extern QString quasselDate; - extern uint quasselBuild; + extern QString quasselBaseVersion; + extern QString quasselBuildDate; + extern uint protocolVersion; - //! Minimum client build number the core needs - extern uint clientBuildNeeded; - extern QString clientVersionNeeded; + extern uint clientNeedsProtocol; //< Minimum protocol version the client needs + extern uint coreNeedsProtocol; //< Minimum protocol version the core needs - //! Minimum core build number the client needs - extern uint coreBuildNeeded; - extern QString coreVersionNeeded; + extern QString quasselGeneratedVersion; //< This is possibly set in version.gen // We need different config (QSettings) files for client and gui, since the core cannot work with GUI types // Set these here. They're used in ClientSettings and CoreSettings. @@ -56,6 +54,7 @@ namespace Global { extern bool DEBUG; void registerMetaTypes(); + void setupVersion(); }; #endif diff --git a/src/common/main.cpp b/src/common/main.cpp index 3c36a280..eca54ba2 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -66,8 +66,7 @@ int main(int argc, char **argv) { // Logger logger; Global::registerMetaTypes(); - -#include "../../version.inc" + Global::setupVersion(); #if defined BUILD_CORE Global::runMode = Global::CoreOnly; diff --git a/src/core/core.cpp b/src/core/core.cpp index f413bbf2..ebfe4914 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -100,7 +100,7 @@ void Core::saveState() { QVariantMap state; QVariantList activeSessions; foreach(UserId user, instance()->sessions.keys()) activeSessions << QVariant::fromValue(user); - state["CoreBuild"] = Global::quasselBuild; + state["CoreStateVersion"] = 1; state["ActiveSessions"] = activeSessions; s.setCoreState(state); } @@ -115,11 +115,13 @@ void Core::restoreState() { return; } CoreSettings s; - uint build = s.coreState().toMap()["CoreBuild"].toUInt(); - if(build < 362) { + /* We don't check, since we are at the first version since switching to Git + uint statever = s.coreState().toMap()["CoreStateVersion"].toUInt(); + if(statever < 1) { qWarning() << qPrintable(tr("Core state too old, ignoring...")); return; } + */ QVariantList activeSessions = s.coreState().toMap()["ActiveSessions"].toList(); if(activeSessions.count() > 0) { qDebug() << "Restoring previous core state..."; @@ -382,16 +384,31 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) { // OK, so we have at least an init message format we can understand if(msg["MsgType"] == "ClientInit") { QVariantMap reply; + + // Just version information -- check it! + if(msg.contains("ClientBuild") && msg["ClientBuild"].toUInt() < 732 + || !msg.contains("ClientBuild") && msg["ProtocolVersion"].toUInt() < Global::coreNeedsProtocol) { + reply["MsgType"] = "ClientInitReject"; + reply["Error"] = tr("Your Quassel Client is too old!
" + "This core needs at least client/core protocol version %1.
" + "Please consider upgrading your client.").arg(Global::coreNeedsProtocol); + SignalProxy::writeDataToDevice(socket, reply); + qWarning() << qPrintable(tr("Client %1 too old, rejecting.").arg(socket->peerAddress().toString())); + socket->close(); return; + } + reply["CoreVersion"] = Global::quasselVersion; - reply["CoreDate"] = Global::quasselDate; - reply["CoreBuild"] = Global::quasselBuild; + reply["CoreDate"] = Global::quasselBuildDate; + reply["CoreBuild"] = 860; // FIXME legacy + reply["ProtocolVersion"] = Global::protocolVersion; // TODO: Make the core info configurable int uptime = startTime.secsTo(QDateTime::currentDateTime()); int updays = uptime / 86400; uptime %= 86400; int uphours = uptime / 3600; uptime %= 3600; int upmins = uptime / 60; - reply["CoreInfo"] = tr("Quassel Core Version %1 (Build ≥ %2)
" - "Up %3d%4h%5m (since %6)").arg(Global::quasselVersion).arg(Global::quasselBuild) + reply["CoreInfo"] = tr("Quassel Core Version %1
" + "Built: %2
" + "Up %3d%4h%5m (since %6)").arg(Global::quasselVersion).arg(Global::quasselBuildDate) .arg(updays).arg(uphours,2,10,QChar('0')).arg(upmins,2,10,QChar('0')).arg(startTime.toString(Qt::TextDate)); #ifndef QT_NO_OPENSSL @@ -407,23 +424,13 @@ void Core::processClientMessage(QTcpSocket *socket, const QVariantMap &msg) { #else bool supportsCompression = false; #endif - + reply["SupportSsl"] = supportSsl; reply["SupportsCompression"] = supportsCompression; // switch to ssl/compression after client has been informed about our capabilities (see below) reply["LoginEnabled"] = true; - // Just version information -- check it! - if(msg["ClientBuild"].toUInt() < Global::clientBuildNeeded) { - reply["MsgType"] = "ClientInitReject"; - reply["Error"] = tr("Your Quassel Client is too old!
" - "This core needs at least client version %1 (Build >= %2).
" - "Please consider upgrading your client.").arg(Global::quasselVersion).arg(Global::quasselBuild); - SignalProxy::writeDataToDevice(socket, reply); - qWarning() << qPrintable(tr("Client %1 too old, rejecting.").arg(socket->peerAddress().toString())); - socket->close(); return; - } // check if we are configured, start wizard otherwise if(!configured) { reply["Configured"] = false; diff --git a/src/core/ctcphandler.cpp b/src/core/ctcphandler.cpp index ba489648..b5dcbd77 100644 --- a/src/core/ctcphandler.cpp +++ b/src/core/ctcphandler.cpp @@ -175,8 +175,8 @@ void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QSt void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) { Q_UNUSED(target) if(ctcptype == CtcpQuery) { - reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC (v%1 build >= %2) -- http://www.quassel-irc.org") - .arg(Global::quasselVersion).arg(Global::quasselBuild)); + reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1, built: %2 -- http://www.quassel-irc.org") + .arg(Global::quasselVersion).arg(Global::quasselBuildDate)); emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix)); } else { // display Version answer diff --git a/src/qtui/aboutdlg.cpp b/src/qtui/aboutdlg.cpp index a32ab6b8..6dfa3c87 100644 --- a/src/qtui/aboutdlg.cpp +++ b/src/qtui/aboutdlg.cpp @@ -24,7 +24,7 @@ AboutDlg::AboutDlg(QWidget *parent) : QDialog(parent) { ui.setupUi(this); - ui.versionLabel->setText(QString("Version %1, Build ≥ %2 (%3)").arg(Global::quasselVersion).arg(Global::quasselBuild).arg(Global::quasselDate)); + ui.versionLabel->setText(QString("Version %1, built %2").arg(Global::quasselVersion).arg(Global::quasselBuildDate)); ui.aboutTextBrowser->setHtml(about()); ui.authorTextBrowser->setHtml(authors()); ui.contributorTextBrowser->setHtml(contributors()); diff --git a/version.inc b/version.inc index 10b10a62..92fc5fd5 100644 --- a/version.inc +++ b/version.inc @@ -1,18 +1,9 @@ // Versioning, should be kept current :) // This is included in main.cpp -{ using namespace Global; +//! This is the fallback version number in case we can't autogenerate one +quasselBaseVersion = "0.3.0-pre"; +protocolVersion = 1; //< Version of the client/core protocol - quasselVersion = "0.3.0-pre"; - quasselDate = "2008-06-04"; - quasselBuild = 869; - - //! Minimum client build number the core needs - clientBuildNeeded = 731; - clientVersionNeeded = quasselVersion; - - //! Minimum core build number the client needs - coreBuildNeeded = 731; - coreVersionNeeded = quasselVersion; - -} +coreNeedsProtocol = 1; //< Minimum protocol version the core needs +clientNeedsProtocol = 1; //< Minimum protocol version the client needs -- 2.20.1