summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-04-11 18:12:51 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2026-04-11 18:12:51 +0100
commit3ce6cf305572709332d7329674ec45c987a093ad (patch)
tree75a018f6dcf929182961bddca7601181fac415e4
parent72bfa9dd305258789b0d2e80f8af13962e5aac42 (diff)
downloadwebstat-3ce6cf305572709332d7329674ec45c987a093ad.tar.bz2
webstat-3ce6cf305572709332d7329674ec45c987a093ad.tar.xz
webstat-3ce6cf305572709332d7329674ec45c987a093ad.zip
Introduce MD5 from libmd, use it for hashing queuedLines for park path
-rw-r--r--Jamroot.jam1
-rw-r--r--src/Jamfile.jam1
-rw-r--r--src/ingestor.cpp30
-rw-r--r--src/logTypes.hpp2
4 files changed, 32 insertions, 2 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index 2f38c94..37e4a0e 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -13,6 +13,7 @@ lib adhocutil : : <link>shared : : <include>/usr/include/adhocutil <library>glib
lib dbppcore : : <link>shared : : <include>/usr/include/dbpp <library>adhocutil ;
lib dbpp-postgresql : : <link>shared : : <include>/usr/include/dbpp-postgresql <library>dbppcore ;
lib z : : <link>shared ;
+lib md : : <link>shared ;
project webstat : requirements
<cxxstd>26
diff --git a/src/Jamfile.jam b/src/Jamfile.jam
index 9459dd8..eca0c24 100644
--- a/src/Jamfile.jam
+++ b/src/Jamfile.jam
@@ -4,6 +4,7 @@ lib webstat : [ glob *.cpp : *_main.cpp ] :
<library>..//dbppcore
<library>../thirdparty//scn
<library>..//z
+ <library>..//md
<library>..//curl
: :
<include>.
diff --git a/src/ingestor.cpp b/src/ingestor.cpp
index 0659f1f..5ae2487 100644
--- a/src/ingestor.cpp
+++ b/src/ingestor.cpp
@@ -24,6 +24,32 @@ namespace DB {
namespace WebStat {
namespace {
+ using ByteArrayView = std::span<const uint8_t>;
+
+ auto
+ bytesToHexRange(const ByteArrayView bytes)
+ {
+ constexpr auto HEXN = 16ZU;
+ return bytes | std::views::transform([](auto byte) {
+ return std::array {byte / HEXN, byte % HEXN};
+ }) | std::views::join
+ | std::views::transform([](auto nibble) {
+ return "0123456789abcdef"[nibble];
+ });
+ }
+
+ EntityHash
+ makeHash(const std::string_view value)
+ {
+ MD5_CTX ctx {};
+ MD5Init(&ctx);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - correct for md5ing raw bytes
+ MD5Update(&ctx, reinterpret_cast<const uint8_t *>(value.data()), value.length());
+ EntityHash hash {};
+ MD5Final(hash.data(), &ctx);
+ return hash;
+ }
+
Crc32Value
crc32(const std::string_view value)
{
@@ -281,8 +307,8 @@ namespace WebStat {
if (queuedLines.empty()) {
return std::unexpected(0);
}
- const std::filesystem::path path {
- settings.fallbackDir / std::format("parked-{}.short", crc32(queuedLines.front()))};
+ const std::filesystem::path path {settings.fallbackDir
+ / std::format("parked-{:s}.short", bytesToHexRange(makeHash(queuedLines.front())))};
if (auto parked = FilePtr(fopen(path.c_str(), "w"))) {
fprintf(parked.get(), "%zu\n", queuedLines.size());
for (const auto & line : queuedLines) {
diff --git a/src/logTypes.hpp b/src/logTypes.hpp
index 71393b2..6556d5c 100644
--- a/src/logTypes.hpp
+++ b/src/logTypes.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <md5.h>
#include <optional>
#include <scn/scan.h>
#include <string>
@@ -35,6 +36,7 @@ namespace WebStat {
};
using Crc32Value = uint32_t;
+ using EntityHash = std::array<uint8_t, MD5_DIGEST_LENGTH>;
using Entity = std::tuple<Crc32Value, EntityType, std::string_view>;
}