You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2019/01/27 11:59:56 UTC
[sling-org-apache-sling-commons-clam] branch master updated:
SLING-8247 Add timestamp a scan was started to ScanResult
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-clam.git
The following commit(s) were added to refs/heads/master by this push:
new ccec31a SLING-8247 Add timestamp a scan was started to ScanResult
ccec31a is described below
commit ccec31adaa85d572a61fc9115a0f0280a168de03
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Sun Jan 27 12:59:20 2019 +0100
SLING-8247 Add timestamp a scan was started to ScanResult
---
pom.xml | 2 +-
.../java/org/apache/sling/commons/clam/ScanResult.java | 9 ++++++++-
.../apache/sling/commons/clam/internal/ClamdService.java | 15 ++++++++-------
.../java/org/apache/sling/commons/clam/package-info.java | 2 +-
4 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/pom.xml b/pom.xml
index 76e9e07..a529440 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
</parent>
<artifactId>org.apache.sling.commons.clam</artifactId>
- <version>1.0.3-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<name>Apache Sling Commons Clam</name>
<description>Service to scan data for malware with ClamAV</description>
diff --git a/src/main/java/org/apache/sling/commons/clam/ScanResult.java b/src/main/java/org/apache/sling/commons/clam/ScanResult.java
index 4ba0d7b..b2dbe58 100644
--- a/src/main/java/org/apache/sling/commons/clam/ScanResult.java
+++ b/src/main/java/org/apache/sling/commons/clam/ScanResult.java
@@ -30,9 +30,12 @@ public class ScanResult {
private final String message;
- public ScanResult(@NotNull final Status status, @NotNull final String message) {
+ private final long started;
+
+ public ScanResult(@NotNull final Status status, @NotNull final String message, long started) {
this.status = status;
this.message = message;
+ this.started = started;
}
public long getTimestamp() {
@@ -49,6 +52,10 @@ public class ScanResult {
return message;
}
+ public long getStarted() {
+ return started;
+ }
+
public boolean isOk() {
return Status.OK.equals(status);
}
diff --git a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
index 581dc0d..f17f385 100644
--- a/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
+++ b/src/main/java/org/apache/sling/commons/clam/internal/ClamdService.java
@@ -96,12 +96,13 @@ public class ClamdService implements ClamService {
@Override
@NotNull
public ScanResult scan(@NotNull final InputStream inputStream) throws IOException {
+ final long started = System.currentTimeMillis();
try {
final byte[] reply = doInstream(inputStream);
- return parseClamdReply(reply);
+ return parseClamdReply(reply, started);
} catch (InstreamSizeLimitExceededException e) {
logger.error("doing INSTREAM failed", e);
- return new ScanResult(ScanResult.Status.ERROR, e.getMessage());
+ return new ScanResult(ScanResult.Status.ERROR, e.getMessage(), started);
}
}
@@ -195,17 +196,17 @@ public class ClamdService implements ClamService {
}
}
- private ScanResult parseClamdReply(final byte[] reply) {
+ private ScanResult parseClamdReply(final byte[] reply, final long started) {
final String message = new String(reply, StandardCharsets.US_ASCII).trim();
logger.info("reply message from clam daemon: '{}'", message);
if (message.matches(OK_REPLY_PATTERN)) {
- return new ScanResult(Status.OK, message);
+ return new ScanResult(Status.OK, message, started);
} else if (message.matches(FOUND_REPLY_PATTERN)) {
- return new ScanResult(Status.FOUND, message);
+ return new ScanResult(Status.FOUND, message, started);
} else if (message.matches(INSTREAM_SIZE_LIMIT_EXCEEDED_PATTERN)) {
- return new ScanResult(Status.ERROR, message);
+ return new ScanResult(Status.ERROR, message, started);
} else {
- return new ScanResult(Status.UNKNOWN, message);
+ return new ScanResult(Status.UNKNOWN, message, started);
}
}
diff --git a/src/main/java/org/apache/sling/commons/clam/package-info.java b/src/main/java/org/apache/sling/commons/clam/package-info.java
index 4417140..848b02a 100644
--- a/src/main/java/org/apache/sling/commons/clam/package-info.java
+++ b/src/main/java/org/apache/sling/commons/clam/package-info.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-@Version("1.0.0")
+@Version("2.0.0")
package org.apache.sling.commons.clam;
import org.osgi.annotation.versioning.Version;