diff options
| author | saturneric <[email protected]> | 2026-09-21 22:44:34 +0200 |
|---|---|---|
| committer | saturneric <[email protected]> | 2026-09-21 22:44:34 +0200 |
| commit | 264af1f1669fceb4a504d2fa32cccc42e512910c (patch) | |
| tree | e8ee3756c19f5e0d879c80da3030e5364977199a /src | |
| parent | style(gpg): improve comments and log messages (diff) | |
| download | modules-264af1f1669fceb4a504d2fa32cccc42e512910c.tar.gz modules-264af1f1669fceb4a504d2fa32cccc42e512910c.zip | |
refactor(gpg-info): migrate to module logging macros
- replace legacy MLogDebug calls with structured logging macros
- preserve diagnostic context while using stream-style log formatting
- add logging API stubs and C++ module ID definitions for tests
- apply formatting updates to email SDK test stubs
Diffstat (limited to 'src')
| -rw-r--r-- | src/m_email/test/EMailCryptoSdkStubs.cpp | 16 | ||||
| -rw-r--r-- | src/m_email/test/EMailSdkStubs.cpp | 24 | ||||
| -rw-r--r-- | src/m_gpg_info/GnuPGInfoGatheringModule.cpp | 73 |
3 files changed, 58 insertions, 55 deletions
diff --git a/src/m_email/test/EMailCryptoSdkStubs.cpp b/src/m_email/test/EMailCryptoSdkStubs.cpp index 8321757..0e322ef 100644 --- a/src/m_email/test/EMailCryptoSdkStubs.cpp +++ b/src/m_email/test/EMailCryptoSdkStubs.cpp @@ -135,6 +135,9 @@ void GFModuleLogDebug(const char*) {} void GFModuleLogInfo(const char*) {} void GFModuleLogWarn(const char*) {} void GFModuleLogError(const char*) {} +void GFModuleLogAt(const char*, int, const char*, int, const char*, + const char*) {} +int GFModuleLogEnabled(const char*, int) { return 1; } char* GFAppActiveLocale() { return GFModuleStrDup("en_US"); } @@ -312,9 +315,7 @@ void GFBufferRelease(GFBufferRef buf) { delete reinterpret_cast<StubBuffer*>(buf); } -size_t GFBufferOutstandingCount(const char*) { - return LiveBuffers().size(); -} +size_t GFBufferOutstandingCount(const char*) { return LiveBuffers().size(); } int GFGpgSign(int, const char* const* key_ids, size_t key_ids_size, GFBufferView in, int sign_mode, int, GFGpgResultRef* out) { @@ -450,8 +451,11 @@ void GFGpgResultRelease(GFGpgResultRef r) { delete impl; } -size_t GFGpgResultOutstandingCount(const char*) { - return LiveResults().size(); -} +size_t GFGpgResultOutstandingCount(const char*) { return LiveResults().size(); } } // extern "C" + +// C++ linkage, deliberately outside the extern "C" block above: GFModule.h +// declares it as an ordinary C++ function, and the log macros call it on every +// line. Defined here with C linkage it compiles cleanly and fails to link. +const char* GFGetModuleID() { return "harness"; } diff --git a/src/m_email/test/EMailSdkStubs.cpp b/src/m_email/test/EMailSdkStubs.cpp index a6a1302..4ecee84 100644 --- a/src/m_email/test/EMailSdkStubs.cpp +++ b/src/m_email/test/EMailSdkStubs.cpp @@ -12,8 +12,14 @@ #include <set> namespace { -std::set<void*>& NormalArena() { static std::set<void*> a; return a; } -std::set<void*>& SecureArena() { static std::set<void*> a; return a; } +std::set<void*>& NormalArena() { + static std::set<void*> a; + return a; +} +std::set<void*>& SecureArena() { + static std::set<void*> a; + return a; +} } // namespace int g_allocator_violations = 0; @@ -51,8 +57,9 @@ void GFSecFreeMemory(void* p) { if (SecureArena().erase(p) == 0) { // Exactly the real crash: a pointer that never came from the secure // allocator handed to the secure deallocator. - std::printf("[FAIL] GFSecFreeMemory on a pointer it does not own " - "(this is the munmap_chunk abort)\n"); + std::printf( + "[FAIL] GFSecFreeMemory on a pointer it does not own " + "(this is the munmap_chunk abort)\n"); ++g_allocator_violations; return; } @@ -111,8 +118,10 @@ void GFModuleLogDebug(const char*) {} void GFModuleLogInfo(const char*) {} void GFModuleLogWarn(const char*) {} void GFModuleLogError(const char*) {} +void GFModuleLogAt(const char*, int, const char*, int, const char*, + const char*) {} +int GFModuleLogEnabled(const char*, int) { return 1; } -const char* GFGetModuleID() { return "harness"; } char* GFAppActiveLocale() { return GFModuleStrDup("en_US"); } unsigned int GFUIMutedTextColor(void*) { return 0xFF808080; } unsigned int GFUIBorderColor(void*) { return 0xFF808080; } @@ -121,3 +130,8 @@ unsigned int GFUIDangerColor(void*) { return 0xFFFF0000; } unsigned int GFUIAccentColor(void*, int) { return 0xFF0066CC; } char* GFUIHumanSize(long long) { return GFModuleStrDup("0 B"); } } + +// C++ linkage, deliberately outside the extern "C" block above: GFModule.h +// declares it as an ordinary C++ function, and the log macros call it on every +// line. Defined here with C linkage it compiles cleanly and fails to link. +const char* GFGetModuleID() { return "harness"; } diff --git a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp index d2543bf..b2242df 100644 --- a/src/m_gpg_info/GnuPGInfoGatheringModule.cpp +++ b/src/m_gpg_info/GnuPGInfoGatheringModule.cpp @@ -179,32 +179,31 @@ auto StartStartGatheringGnuPGComponentsInfo(const QString &gpgme_version, QStringListToCharArray({"--homedir", default_home_path, "--list-components"}), GetGpgComponentInfos, &context); - MLogDebug("loading gnupg component info done."); + LOG_DEBUG("loading gnupg component info done."); return 0; } auto StartGatheringAllGnuPGInfo() -> int { const auto gpgme_version = UDUP(GFModuleRetrieveRTValueOrDefault("core", "gpgme.version", "0.0.0")); - MLogDebug(QString("got gpgme version from rt: %1").arg(gpgme_version)); + LOG_D() << "got gpgme version from rt:" << gpgme_version; const auto gpgconf_path = UDUP( GFModuleRetrieveRTValueOrDefault("core", "gpgme.ctx.gpgconf_path", "")); - MLogDebug(QString("got gpgconf path from rt: %1").arg(gpgconf_path)); + LOG_D() << "got gpgconf path from rt:" << gpgconf_path; if (gpgconf_path.isEmpty()) { - MLogDebug("gpgconf path is empty, skip gathering gnupg info."); + LOG_DEBUG("gpgconf path is empty, skip gathering gnupg info."); return -1; } auto default_home_path = UDUP(GFModuleRetrieveRTValueOrDefault( "core", "gpgme.ctx.default_database_path", "")); - MLogDebug( - QString("got default home path from rt: %1").arg(default_home_path)); + LOG_D() << "got default home path from rt:" << default_home_path; default_home_path = QDir::toNativeSeparators( QFileInfo(default_home_path).canonicalFilePath()); - MLogDebug(QString("final default home path: %1").arg(default_home_path)); + LOG_D() << "final default home path:" << default_home_path; // gather component information StartStartGatheringGnuPGComponentsInfo(gpgme_version, gpgconf_path, @@ -250,8 +249,7 @@ auto StartGatheringAllGnuPGInfo() -> int { assert(jsonlized_component_info.isObject()); auto component_info = GpgComponentInfo(jsonlized_component_info.object()); - MLogDebug(QString("gpgconf check options ready, component: %1") - .arg(component_info.name)); + LOG_T() << "gpgconf check options ready, component:" << component_info.name; if (component_info.name == "gpgme" || component_info.name == "gpgconf") { continue; @@ -280,18 +278,16 @@ auto CalculateBinaryChecksum(const QString &path) -> std::optional<QString> { // Check the file's existence and access rights. QFileInfo const info(path); if (!info.exists() || !info.isFile() || !info.isReadable()) { - MLogDebug(QString("get info for file %1 error, exists: %2") - .arg(info.filePath()) - .arg(info.exists())); + LOG_D() << "get info for file" << info.filePath() + << "error, exists:" << info.exists(); return {}; } // Open and read the file. QFile f(info.filePath()); if (!f.open(QIODevice::ReadOnly)) { - MLogDebug(QString("open %1 to calculate checksum error: %2") - .arg(path) - .arg(f.errorString())); + LOG_D() << "open" << path + << "to calculate checksum error:" << f.errorString(); return {}; } @@ -302,8 +298,7 @@ auto CalculateBinaryChecksum(const QString &path) -> std::optional<QString> { while (!f.atEnd()) { QByteArray const buffer = f.read(buffer_size); if (buffer.isEmpty()) { - MLogDebug(QString("error reading file %1 during checksum calculation") - .arg(path)); + LOG_D() << "error reading file" << path << "during checksum calculation"; return {}; } hash_sha.addData(buffer); @@ -322,15 +317,12 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out, auto p_out = QString::fromUtf8(out); auto p_err = QString::fromUtf8(err); - MLogDebug(QString("gpgconf components exit_code: %1 process stdout size: %2") - .arg(exit_code) - .arg(p_out.size())); + LOG_D() << "gpgconf components exit_code:" << exit_code + << "process stdout size:" << p_out.size(); if (exit_code != 0) { - MLogDebug( - QString("gpgconf execute error, process stderr: %1, process stdout: %2") - .arg(p_err) - .arg(p_out)); + LOG_D() << "gpgconf execute error, process stderr:" << p_err + << "process stdout:" << p_out; return; } @@ -383,12 +375,10 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out, auto binary_checksum = CalculateBinaryChecksum(component_path); - MLogDebug( - QString("gnupg component name: %1 desc: %2 checksum: %3 path: %4") - .arg(component_name) - .arg(component_desc) - .arg(binary_checksum.has_value() ? binary_checksum.value() : "/", - component_path)); + LOG_D() << "gnupg component name:" << component_name + << "desc:" << component_desc << "checksum:" + << (binary_checksum.has_value() ? binary_checksum.value() : "/") + << "path:" << component_path; QString version = "/"; @@ -429,7 +419,7 @@ void GetGpgComponentInfos(void *data, int exit_code, const char *out, component_infos.push_back(c_i); } - MLogDebug("load gnupg component info actually done."); + LOG_DEBUG("load gnupg component info actually done."); } } @@ -443,9 +433,8 @@ void GetGpgDirectoryInfos(void *, int exit_code, const char *out, for (const auto &line : line_split_list) { auto info_split_list = line.split(":"); - MLogDebug(QString("gpgconf directories info line: %1 info size: %2") - .arg(line) - .arg(info_split_list.size())); + LOG_T() << "gpgconf directories info line:" << line + << "info size:" << info_split_list.size(); if (info_split_list.size() != 2) continue; @@ -480,12 +469,9 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, auto *context = reinterpret_cast<Context *>(data); auto component_name = context->component_info.name; - MLogDebug( - QString( - "gpgconf %1 available options exit_code: %2 process stdout size: %3") - .arg(component_name) - .arg(exit_code) - .arg(p_out.size())); + LOG_D() << "gpgconf" << component_name + << "available options exit_code:" << exit_code + << "process stdout size:" << p_out.size(); std::vector<GpgOptionsInfo> options_infos; @@ -494,10 +480,9 @@ void GetGpgOptionInfos(void *data, int exit_code, const char *out, for (const auto &line : line_split_list) { auto info_split_list = line.split(":"); - MLogDebug(QString("component %1 available options line: %2 info size: %3") - .arg(component_name) - .arg(line) - .arg(info_split_list.size())); + LOG_T() << "component" << component_name + << "available options line:" << line + << "info size:" << info_split_list.size(); if (info_split_list.size() < 10) continue; |
