Introduce new format for version.inc.
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 7 Jun 2008 22:14:57 +0000 (00:14 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 7 Jun 2008 22:14:57 +0000 (00:14 +0200)
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
src/common/CMakeLists.txt
src/common/global.cpp
src/common/global.h
src/common/main.cpp
src/core/core.cpp
src/core/ctcphandler.cpp
src/qtui/aboutdlg.cpp
version.inc

index e7f68b0..93d73bb 100644 (file)
@@ -157,8 +157,9 @@ void ClientSyncer::coreSocketConnected() {
   QVariantMap clientInit;
   clientInit["MsgType"] = "ClientInit";
   clientInit["ClientVersion"] = Global::quasselVersion;
   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;
   clientInit["UseSsl"] = coreConnectionInfo["useSsl"];
 #ifndef QT_NO_COMPRESS
   clientInit["UseCompression"] = true;
@@ -166,7 +167,6 @@ void ClientSyncer::coreSocketConnected() {
   clientInit["UseCompression"] = false;
 #endif
 
   clientInit["UseCompression"] = false;
 #endif
 
-  
   SignalProxy::writeDataToDevice(socket, clientInit);
 }
 
   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...
 
 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("<b>The Quassel Core you are trying to connect to is too old!</b><br>"
     emit connectionError(tr("<b>The Quassel Core you are trying to connect to is too old!</b><br>"
-        "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;
   }
     disconnectFromCore();
     return;
   }
index 72e4eb1..2dcabbe 100644 (file)
@@ -37,4 +37,6 @@ set(HEADERS
 
 qt4_wrap_cpp(MOC ${HEADERS})
 
 
 qt4_wrap_cpp(MOC ${HEADERS})
 
+include_directories(${CMAKE_SOURCE_DIR}) # for version.inc and version.gen
+
 add_library(mod_common STATIC ${SOURCES} ${MOC})
 add_library(mod_common STATIC ${SOURCES} ${MOC})
index 59afde1..a062886 100644 (file)
@@ -98,15 +98,36 @@ void Global::registerMetaTypes() {
   qRegisterMetaTypeStreamOperators<MsgId>("MsgId");
 }
 
   qRegisterMetaTypeStreamOperators<MsgId>("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;
 // 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;
 
 Global::RunMode Global::runMode;
 uint Global::defaultPort;
index 0759c27..65d1110 100644 (file)
 namespace Global {
 
   extern QString quasselVersion;
 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.
 
   // 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();
   extern bool DEBUG;
 
   void registerMetaTypes();
+  void setupVersion();
 };
 
 #endif
 };
 
 #endif
index 3c36a28..eca54ba 100644 (file)
@@ -66,8 +66,7 @@ int main(int argc, char **argv) {
   // Logger logger;
 
   Global::registerMetaTypes();
   // Logger logger;
 
   Global::registerMetaTypes();
-
-#include "../../version.inc"
+  Global::setupVersion();
 
 #if defined BUILD_CORE
   Global::runMode = Global::CoreOnly;
 
 #if defined BUILD_CORE
   Global::runMode = Global::CoreOnly;
index f413bbf..ebfe491 100644 (file)
@@ -100,7 +100,7 @@ void Core::saveState() {
   QVariantMap state;
   QVariantList activeSessions;
   foreach(UserId user, instance()->sessions.keys()) activeSessions << QVariant::fromValue<UserId>(user);
   QVariantMap state;
   QVariantList activeSessions;
   foreach(UserId user, instance()->sessions.keys()) activeSessions << QVariant::fromValue<UserId>(user);
-  state["CoreBuild"] = Global::quasselBuild;
+  state["CoreStateVersion"] = 1;
   state["ActiveSessions"] = activeSessions;
   s.setCoreState(state);
 }
   state["ActiveSessions"] = activeSessions;
   s.setCoreState(state);
 }
@@ -115,11 +115,13 @@ void Core::restoreState() {
     return;
   }
   CoreSettings s;
     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;
   }
     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...";
   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;
   // 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("<b>Your Quassel Client is too old!</b><br>"
+      "This core needs at least client/core protocol version %1.<br>"
+      "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["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;
     // 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("<b>Quassel Core Version %1 (Build &ge; %2)</b><br>"
-                            "Up %3d%4h%5m (since %6)").arg(Global::quasselVersion).arg(Global::quasselBuild)
+    reply["CoreInfo"] = tr("<b>Quassel Core Version %1</b><br>"
+                            "Built: %2<br>"
+                            "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
                             .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
 #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;
 
     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("<b>Your Quassel Client is too old!</b><br>"
-                          "This core needs at least client version %1 (Build >= %2).<br>"
-                          "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;
     // check if we are configured, start wizard otherwise
     if(!configured) {
       reply["Configured"] = false;
index ba48964..b5dcbd7 100644 (file)
@@ -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 &param) {
   Q_UNUSED(target)
   if(ctcptype == CtcpQuery) {
 void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString &param) {
   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
     emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
   } else {
     // display Version answer
index a32ab6b..6dfa3c8 100644 (file)
@@ -24,7 +24,7 @@
 AboutDlg::AboutDlg(QWidget *parent) : QDialog(parent) {
   ui.setupUi(this);
 
 AboutDlg::AboutDlg(QWidget *parent) : QDialog(parent) {
   ui.setupUi(this);
 
-  ui.versionLabel->setText(QString("<b>Version %1, Build &ge; %2 (%3)</b>").arg(Global::quasselVersion).arg(Global::quasselBuild).arg(Global::quasselDate));
+  ui.versionLabel->setText(QString("<b>Version %1, built %2</b>").arg(Global::quasselVersion).arg(Global::quasselBuildDate));
   ui.aboutTextBrowser->setHtml(about());
   ui.authorTextBrowser->setHtml(authors());
   ui.contributorTextBrowser->setHtml(contributors());
   ui.aboutTextBrowser->setHtml(about());
   ui.authorTextBrowser->setHtml(authors());
   ui.contributorTextBrowser->setHtml(contributors());
index 10b10a6..92fc5fd 100644 (file)
@@ -1,18 +1,9 @@
 // Versioning, should be kept current :)
 // This is included in main.cpp
 
 // 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