Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_antivirus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-04-07 15:50:11 +0300
committerRobin Appelman <robin@icewind.nl>2022-04-13 15:21:12 +0300
commitc66683860324499a41dc8eb777da01d1d7e0de1d (patch)
tree4cc4b7a462c21f3283766aafb7cb4373c3c8c633 /lib
parentdc31bc6e5586def26a4d82fbbe671359d488b00c (diff)
make connect timeout and chunk size configurable
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppConfig.php6
-rw-r--r--lib/ICAP/ICAPClient.php12
-rw-r--r--lib/Scanner/ICAP.php6
3 files changed, 13 insertions, 11 deletions
diff --git a/lib/AppConfig.php b/lib/AppConfig.php
index d12043e..3092de8 100644
--- a/lib/AppConfig.php
+++ b/lib/AppConfig.php
@@ -14,12 +14,14 @@ use OCP\IConfig;
* @method string getAvMode()
* @method string getAvSocket()
* @method string getAvHost()
- * @method int getAvPort()
+ * @method string getAvPort()
* @method string getAvCmdOptions()
* @method string getAvPath()
* @method string getAvInfectedAction()
* @method string getAvIcapRequestService()
* @method string getAvIcapResponseHeader()
+ * @method string getAvIcapChunkSize()
+ * @method string getAvIcapConnectTimeout()
*
* @method null setAvMode(string $avMode)
* @method null setAvSocket(string $avsocket)
@@ -51,6 +53,8 @@ class AppConfig {
'av_background_scan' => 'on',
'av_icap_request_service' => 'avscan',
'av_icap_response_header' => 'X-Infection-Found',
+ 'av_icap_chunk_size' => '1048576',
+ 'av_icap_connect_timeout' => '5',
];
/**
diff --git a/lib/ICAP/ICAPClient.php b/lib/ICAP/ICAPClient.php
index f15d670..73346ae 100644
--- a/lib/ICAP/ICAPClient.php
+++ b/lib/ICAP/ICAPClient.php
@@ -28,16 +28,12 @@ use RuntimeException;
class ICAPClient {
private string $host;
private int $port;
+ private int $connectTimeout;
- /**
- * Constructor
- *
- * @param string $host IP address of ICAP server
- * @param int $port Port number
- */
- public function __construct(string $host, int $port) {
+ public function __construct(string $host, int $port, int $connectTimeout) {
$this->host = $host;
$this->port = $port;
+ $this->connectTimeout = $connectTimeout;
}
/**
@@ -50,7 +46,7 @@ class ICAPClient {
"tcp://{$this->host}:{$this->port}",
$errorCode,
$errorMessage,
- 5
+ $this->connectTimeout
);
if (!$stream) {
diff --git a/lib/Scanner/ICAP.php b/lib/Scanner/ICAP.php
index 5402a25..4c94f9d 100644
--- a/lib/Scanner/ICAP.php
+++ b/lib/Scanner/ICAP.php
@@ -36,6 +36,7 @@ class ICAP extends ScannerBase {
private ?ICAPRequest $request;
private string $service;
private string $virusHeader;
+ private int $chunkSize;
public function __construct(
AppConfig $config,
@@ -48,11 +49,12 @@ class ICAP extends ScannerBase {
$avPort = $this->appConfig->getAvPort();
$this->service = $config->getAvIcapRequestService();
$this->virusHeader = $config->getAvIcapResponseHeader();
+ $this->chunkSize = (int)$config->getAvIcapChunkSize();
if (!($avHost && $avPort)) {
throw new \RuntimeException('The ICAP port and host are not set up.');
}
- $this->icapClient = new ICAPClient($avHost, (int)$avPort);
+ $this->icapClient = new ICAPClient($avHost, (int)$avPort, (int)$config->getAvIcapConnectTimeout());
}
public function initScanner() {
@@ -67,7 +69,7 @@ class ICAP extends ScannerBase {
}
protected function writeChunk($chunk) {
- if (ftell($this->writeHandle) > 1024 * 1024) {
+ if (ftell($this->writeHandle) > $this->chunkSize) {
$this->flushBuffer();
}
parent::writeChunk($chunk);