mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user