Skip to content

Commit

Permalink
Merge branch 'develop' for v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjo-blur committed Dec 4, 2013
2 parents 647e91d + 7ea0894 commit 5830691
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
40 changes: 36 additions & 4 deletions src/Quahog/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public function scanFile($file)
{
$this->_sendCommand('SCAN ' . $file);

return $this->_receiveResponse();
$response = $this->_receiveResponse();

return $this->_parseResponse($response);
}

/**
Expand All @@ -121,7 +123,9 @@ public function multiscanFile($file)
{
$this->_sendCommand('MULTISCAN ' . $file);

return $this->_receiveResponse();
$response = $this->_receiveResponse();

return $this->_parseResponse($response);
}

/**
Expand All @@ -134,7 +138,9 @@ public function contScan($file)
{
$this->_sendCommand('CONTSCAN ' . $file);

return $this->_receiveResponse();
$response = $this->_receiveResponse();

return $this->_parseResponse($response);
}

/**
Expand Down Expand Up @@ -162,7 +168,9 @@ public function scanStream($stream, $maxChunkSize = 1024)

$this->_socket->send(pack('N', 0), MSG_DONTROUTE);

return $this->_receiveResponse();
$response = $this->_receiveResponse();

return $this->_parseResponse($response);
}

/**
Expand All @@ -188,4 +196,28 @@ private function _receiveResponse()

return trim($result);
}

/**
* Parse the received response into a structured array ($filename, $reason, $status)
*
* @param string $response
* @return array
*/
private function _parseResponse($response)
{
$splitResponse = explode(': ', $response);

$filename = $splitResponse[0];
$message = $splitResponse[1];

if ($message === 'OK') {
return array($filename, '', 'OK');
} else {
$parts = explode(' ', $message);
$status = array_pop($parts);
$reason = implode(' ', $parts);

return array($filename, $reason, $status);
}
}
}
9 changes: 5 additions & 4 deletions tests/QuahogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,22 @@ public function testScanFile()
{
$result = $this->quahog->scanFile('/tmp/quahog/EICAR');

$this->assertSame('/tmp/quahog/EICAR: Eicar-Test-Signature FOUND', $result);
$this->assertSame(array('/tmp/quahog/EICAR', 'Eicar-Test-Signature', 'FOUND'), $result);
}

public function testMultiscanFile()
{
$result = $this->quahog->multiscanFile('/tmp/quahog');

$this->assertTrue((strpos($result, 'Eicar-Test-Signature FOUND') !== false), $result);
$this->assertSame('Eicar-Test-Signature', $result[1]);
$this->assertSame('FOUND', $result[2]);
}

public function testContScan()
{
$result = $this->quahog->contScan('/tmp/quahog');

$this->assertStringStartsWith('/tmp/quahog/EICAR: Eicar-Test-Signature FOUND', $result);
$this->assertSame(array('/tmp/quahog/EICAR', 'Eicar-Test-Signature', 'FOUND'), $result);
}

public function testScanStream()
Expand All @@ -111,7 +112,7 @@ public function testScanStream()

$result = $this->quahog->scanStream($stream);

$this->assertSame('stream: Eicar-Test-Signature FOUND', $result);
$this->assertSame(array('stream', 'Eicar-Test-Signature', 'FOUND'), $result);
}

public function testShutdown()
Expand Down

0 comments on commit 5830691

Please sign in to comment.