]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add macros to check if transaction log file version is new enough.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 30 Mar 2017 17:38:44 +0000 (20:38 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 3 Apr 2017 11:00:04 +0000 (14:00 +0300)
The version numbers are 8bit, so we can generate a single 16bit number out
of them.

src/lib-index/mail-transaction-log-file.c
src/lib-index/mail-transaction-log.h

index 7da4ca5349f8e56b4dc15fc1d71585e88dd4a0d1..f388846b43e36cdf152c817cc47e598677b3a729 100644 (file)
@@ -529,7 +529,9 @@ mail_transaction_log_file_read_hdr(struct mail_transaction_log_file *file,
                return 0;
        }
 
-       if (file->hdr.minor_version >= 2 || file->hdr.major_version > 1) {
+       const unsigned int hdr_version =
+               MAIL_TRANSACTION_LOG_HDR_VERSION(&file->hdr);
+       if (MAIL_TRANSACTION_LOG_VERSION_HAVE(hdr_version, COMPAT_FLAGS)) {
                /* we have compatibility flags */
                enum mail_index_header_compat_flags compat_flags = 0;
 
index f1e997309b05ac07302f07304dd2f84778bc7a01..b18046748028bd41cd51952a9b13b421bc5641b7 100644 (file)
@@ -9,6 +9,16 @@
 #define MAIL_TRANSACTION_LOG_MINOR_VERSION 2
 #define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
 
+#define MAIL_TRANSACTION_LOG_VERSION_FULL(major, minor) \
+       ((major) << 8 | (minor))
+#define MAIL_TRANSACTION_LOG_VERSION_HAVE(version, wanted_feature) \
+       ((version) >= MAIL_TRANSACTION_LOG_VERSION_##wanted_feature)
+#define MAIL_TRANSACTION_LOG_HDR_VERSION(hdr) \
+       MAIL_TRANSACTION_LOG_VERSION_FULL((hdr)->major_version, (hdr)->minor_version)
+
+#define MAIL_TRANSACTION_LOG_VERSION_COMPAT_FLAGS \
+       MAIL_TRANSACTION_LOG_VERSION_FULL(1, 2)
+
 struct mail_transaction_log_header {
        uint8_t major_version;
        uint8_t minor_version;