From fc3aaac57d7eba8ebb6ce62128a3f3041691693e Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 2 Feb 2025 15:52:53 +0200 Subject: [PATCH 1/2] Implement support for RELOAD and STATS commands --- nClam/ClamClient.cs | 28 ++++++++++++++++++++++++---- nClam/IClamClient.cs | 13 +++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/nClam/ClamClient.cs b/nClam/ClamClient.cs index bfc96e5..b2e456a 100644 --- a/nClam/ClamClient.cs +++ b/nClam/ClamClient.cs @@ -162,10 +162,10 @@ private async Task SendStreamFileChunksAsync(ReadOnlyMemory sourceData, St while (readByteCount < sourceData.Length) { - var toRead = ((sourceData.Length - readByteCount) > MaxChunkSize ? MaxChunkSize : sourceData.Length - readByteCount); - var readBytes = BitConverter.GetBytes((uint) System.Net.IPAddress.HostToNetworkOrder(toRead)); - - await clamStream.WriteAsync(readBytes, 0, readBytes.Length, cancellationToken).ConfigureAwait(false); + var toRead = ((sourceData.Length - readByteCount) > MaxChunkSize ? MaxChunkSize : sourceData.Length - readByteCount); + var readBytes = BitConverter.GetBytes((uint) System.Net.IPAddress.HostToNetworkOrder(toRead)); + + await clamStream.WriteAsync(readBytes, 0, readBytes.Length, cancellationToken).ConfigureAwait(false); await clamStream.WriteAsync(sourceData.Slice(readByteCount, toRead), cancellationToken).ConfigureAwait(false); readByteCount += toRead; @@ -395,5 +395,25 @@ public async Task Shutdown(CancellationToken cancellationToken) { await ExecuteClamCommandAsync("SHUTDOWN", cancellationToken).ConfigureAwait(false); } + + /// + /// Reload the virus databases. + /// + /// cancellation token used for request + public async Task ReloadDb(CancellationToken cancellationToken) + { + await ExecuteClamCommandAsync("RELOAD", cancellationToken).ConfigureAwait(false); + } + + /// + /// Replies with statistics about the scan queue, contents of scan queue, and memory usage. + /// + /// cancellation token used for request + /// + public async Task Stats(CancellationToken cancellationToken) + { + var stats = await ExecuteClamCommandAsync("STATS", cancellationToken).ConfigureAwait(false); + return stats; + } } } diff --git a/nClam/IClamClient.cs b/nClam/IClamClient.cs index edd391e..49a7459 100644 --- a/nClam/IClamClient.cs +++ b/nClam/IClamClient.cs @@ -139,5 +139,18 @@ public interface IClamClient /// Shuts down the ClamAV server in an orderly fashion. /// Task Shutdown(CancellationToken cancellationToken); + + /// + /// Reload the virus databases. + /// + /// cancellation token used for request + Task ReloadDb(CancellationToken cancellationToken); + + /// + /// Replies with statistics about the scan queue, contents of scan queue, and memory usage. + /// + /// cancellation token used for request + /// + Task Stats(CancellationToken cancellationToken); } } \ No newline at end of file From ba05c446fc9b8e32fc3b2c7d1677dda748bf853d Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 2 Feb 2025 16:13:17 +0200 Subject: [PATCH 2/2] STATS implementation has already existed but was not exposed in the interface --- nClam/ClamClient.cs | 12 +----------- nClam/IClamClient.cs | 6 ++---- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/nClam/ClamClient.cs b/nClam/ClamClient.cs index b2e456a..5c08cb0 100644 --- a/nClam/ClamClient.cs +++ b/nClam/ClamClient.cs @@ -404,16 +404,6 @@ public async Task ReloadDb(CancellationToken cancellationToken) { await ExecuteClamCommandAsync("RELOAD", cancellationToken).ConfigureAwait(false); } - - /// - /// Replies with statistics about the scan queue, contents of scan queue, and memory usage. - /// - /// cancellation token used for request - /// - public async Task Stats(CancellationToken cancellationToken) - { - var stats = await ExecuteClamCommandAsync("STATS", cancellationToken).ConfigureAwait(false); - return stats; - } + } } diff --git a/nClam/IClamClient.cs b/nClam/IClamClient.cs index 49a7459..cd9f20e 100644 --- a/nClam/IClamClient.cs +++ b/nClam/IClamClient.cs @@ -147,10 +147,8 @@ public interface IClamClient Task ReloadDb(CancellationToken cancellationToken); /// - /// Replies with statistics about the scan queue, contents of scan queue, and memory usage. + /// Gets the ClamAV server stats /// - /// cancellation token used for request - /// - Task Stats(CancellationToken cancellationToken); + Task GetStatsAsync(CancellationToken cancellationToken); } } \ No newline at end of file