Fix server version (#195)

* modify the way server_version int is built to include build number

* clang

* Update BuildInfo_test.cpp

* clang-format

* Update BuildInfo_test.cpp

* clang-format

* Update BuildInfo_test.cpp

---------

Co-authored-by: Denis Angell <dangell@transia.co>
This commit is contained in:
RichardAH
2023-11-16 16:20:32 +01:00
committed by GitHub
parent b74697ff9a
commit 98833e4934
2 changed files with 46 additions and 1 deletions

View File

@@ -139,6 +139,14 @@ encodeSoftwareVersion(char const* versionStr)
if (v.parse(std::string(versionStr)))
{
// substract year, unless this cases a wrap around
{
auto prev = v.majorVersion;
v.majorVersion -= 2023;
if (prev < v.majorVersion)
v.majorVersion = prev;
}
if (v.majorVersion >= 0 && v.majorVersion <= 255)
c |= static_cast<std::uint64_t>(v.majorVersion) << 40;
@@ -192,6 +200,29 @@ encodeSoftwareVersion(char const* versionStr)
}
}
// extract and append build number as the final two bytes
auto extractBuildNumber =
[](const std::string& str) noexcept -> std::optional<uint16_t> {
size_t plusPos = str.find('+');
if (plusPos == std::string::npos || plusPos == str.length() - 1)
return std::nullopt;
std::string numStr = str.substr(plusPos + 1);
uint64_t buildNum = 0;
for (char c : numStr)
{
if (!isdigit(c))
return std::nullopt;
buildNum = (buildNum * 10 + (c - '0')) & 0xFFFF;
}
return static_cast<uint16_t>(buildNum); // Explicitly cast to uint16_t
};
c |= extractBuildNumber(versionStr).value_or(0);
return c;
}

View File

@@ -41,7 +41,7 @@ public:
// 0x010203
BEAST_EXPECT(
(encodedVersion & 0x0000'FFFF'FF00'0000LLU) ==
0x0000'0102'0300'0000LLU);
0x0000'0002'0300'0000LLU);
// the next two bits:
{
@@ -100,6 +100,20 @@ public:
auto vMax = BuildInfo::encodeSoftwareVersion("9999.12.30");
BEAST_EXPECT(BuildInfo::isNewerVersion(vMax));
auto vRelease1 = BuildInfo::encodeSoftwareVersion("2023.1.1-release+1");
auto vRelease2 = BuildInfo::encodeSoftwareVersion("2023.1.1-release+2");
auto vRelease3 = BuildInfo::encodeSoftwareVersion("2023.1.2-release+2");
auto vRelease4 = BuildInfo::encodeSoftwareVersion("2023.2.1-release+2");
auto vRelease5 = BuildInfo::encodeSoftwareVersion("2024.1.1-release+1");
auto vRelease6 = BuildInfo::encodeSoftwareVersion("2024.1.1-release+2");
BEAST_EXPECT(vMax > vRelease1);
BEAST_EXPECT(vRelease2 > vRelease1);
BEAST_EXPECT(vRelease3 > vRelease2);
BEAST_EXPECT(vRelease4 > vRelease3);
BEAST_EXPECT(vRelease5 > vRelease4);
BEAST_EXPECT(vRelease6 > vRelease2);
}
void