From a516d68982a4fd85804889a2abf72a8995186186 Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Sun, 3 Jun 2018 19:47:55 +0100 Subject: [PATCH 1/6] Move the CHUNK_SIZE contant to the package file that uses it. --- clamd.go | 1 + conn.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/clamd.go b/clamd.go index 5199f63..7c45eb6 100644 --- a/clamd.go +++ b/clamd.go @@ -38,6 +38,7 @@ const ( RES_FOUND = "FOUND" RES_ERROR = "ERROR" RES_PARSE_ERROR = "PARSE ERROR" + CHUNK_SIZE = 1024 ) type Clamd struct { diff --git a/conn.go b/conn.go index 5c9f7f9..752ef32 100644 --- a/conn.go +++ b/conn.go @@ -37,7 +37,6 @@ import ( "time" ) -const CHUNK_SIZE = 1024 const TCP_TIMEOUT = time.Second * 2 var resultRegex = regexp.MustCompile( From 1b1836888a4144da7ddf2e6c38cc8220cefb87af Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Sun, 3 Jun 2018 20:10:47 +0100 Subject: [PATCH 2/6] Make the recievers variables consistent in conn.go --- conn.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index 752ef32..1646e68 100644 --- a/conn.go +++ b/conn.go @@ -80,11 +80,11 @@ func (conn *CLAMDConn) sendChunk(data []byte) error { return err } -func (c *CLAMDConn) readResponse() (chan *ScanResult, *sync.WaitGroup, error) { +func (conn *CLAMDConn) readResponse() (chan *ScanResult, *sync.WaitGroup, error) { var wg sync.WaitGroup wg.Add(1) - reader := bufio.NewReader(c) + reader := bufio.NewReader(conn) ch := make(chan *ScanResult) go func() { From 412684d524724ea0c2fc2538f0df93e9ed50fe54 Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Sun, 3 Jun 2018 20:18:54 +0100 Subject: [PATCH 3/6] Removed some unreachable code --- clamd.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/clamd.go b/clamd.go index 7c45eb6..717fe42 100644 --- a/clamd.go +++ b/clamd.go @@ -123,8 +123,6 @@ func (c *Clamd) Ping() error { return errors.New(fmt.Sprintf("Invalid response, got %s.", s)) } } - - return nil } /* @@ -186,8 +184,6 @@ func (c *Clamd) Reload() error { return errors.New(fmt.Sprintf("Invalid response, got %s.", s)) } } - - return nil } func (c *Clamd) Shutdown() error { From e596f94e8b26da11eba98cf641edeff03492bf28 Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Sun, 3 Jun 2018 20:25:59 +0100 Subject: [PATCH 4/6] Make clamd.go a little more DRY. --- clamd.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/clamd.go b/clamd.go index 717fe42..690a9c3 100644 --- a/clamd.go +++ b/clamd.go @@ -105,6 +105,11 @@ func (c *Clamd) simpleCommand(command string) (chan *ScanResult, error) { return ch, err } +func (c *Clamd) simpleCommandWithPath(commandName string, path string) (chan *ScanResult, error) { + command := fmt.Sprintf("%s %s", commandName, path) + return c.simpleCommand(command) +} + /* Check the daemon's state (should reply with PONG). */ @@ -200,9 +205,7 @@ Scan file or directory (recursively) with archive support enabled (a full path i required). */ func (c *Clamd) ScanFile(path string) (chan *ScanResult, error) { - command := fmt.Sprintf("SCAN %s", path) - ch, err := c.simpleCommand(command) - return ch, err + return c.simpleCommandWithPath("Scan", path) } /* @@ -210,9 +213,7 @@ Scan file or directory (recursively) with archive and special file support disab (a full path is required). */ func (c *Clamd) RawScanFile(path string) (chan *ScanResult, error) { - command := fmt.Sprintf("RAWSCAN %s", path) - ch, err := c.simpleCommand(command) - return ch, err + return c.simpleCommandWithPath("RAWSCAN", path) } /* @@ -220,9 +221,7 @@ Scan file in a standard way or scan directory (recursively) using multiple threa (to make the scanning faster on SMP machines). */ func (c *Clamd) MultiScanFile(path string) (chan *ScanResult, error) { - command := fmt.Sprintf("MULTISCAN %s", path) - ch, err := c.simpleCommand(command) - return ch, err + return c.simpleCommandWithPath("MULTISCAN", path) } /* @@ -230,9 +229,7 @@ Scan file or directory (recursively) with archive support enabled and don’t st the scanning when a virus is found. */ func (c *Clamd) ContScanFile(path string) (chan *ScanResult, error) { - command := fmt.Sprintf("CONTSCAN %s", path) - ch, err := c.simpleCommand(command) - return ch, err + return c.simpleCommandWithPath("CONTSCAN", path) } /* @@ -240,9 +237,7 @@ Scan file or directory (recursively) with archive support enabled and don’t st the scanning when a virus is found. */ func (c *Clamd) AllMatchScanFile(path string) (chan *ScanResult, error) { - command := fmt.Sprintf("ALLMATCHSCAN %s", path) - ch, err := c.simpleCommand(command) - return ch, err + return c.simpleCommandWithPath("ALLMATCHSCAN", path) } /* From 57f78354a9c695eb035b72dc48b46fc1c2229e4f Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Sun, 3 Jun 2018 20:35:10 +0100 Subject: [PATCH 5/6] Tidy up Shutdown() also added some Docs --- clamd.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/clamd.go b/clamd.go index 690a9c3..d2f28d8 100644 --- a/clamd.go +++ b/clamd.go @@ -191,13 +191,12 @@ func (c *Clamd) Reload() error { } } -func (c *Clamd) Shutdown() error { - _, err := c.simpleCommand("SHUTDOWN") - if err != nil { - return err - } - - return err +/* +Sends the SHUTDOWN command to the ClamdAV instance +*/ +func (c *Clamd) Shutdown() (err error) { + _, err = c.simpleCommand("SHUTDOWN") + return } /* From 5778b84b032e961acd035254317dbf9edd9bdd16 Mon Sep 17 00:00:00 2001 From: Stuart Skelton Date: Sun, 3 Jun 2018 20:36:35 +0100 Subject: [PATCH 6/6] Removed a useless TempVar from NewClamd() --- clamd.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clamd.go b/clamd.go index d2f28d8..fa5a9e3 100644 --- a/clamd.go +++ b/clamd.go @@ -297,6 +297,5 @@ func (c *Clamd) ScanStream(r io.Reader, abort chan bool) (chan *ScanResult, erro } func NewClamd(address string) *Clamd { - clamd := &Clamd{address: address} - return clamd + return &Clamd{address: address} }