13 require_once
"./Services/VirusScanner/classes/class.ilVirusScanner.php";
34 $this->host = IL_ICAP_HOST;
35 $this->port = IL_ICAP_PORT;
61 if (!array_key_exists(
'Host', $headers)) {
64 if (!array_key_exists(
'User-Agent', $headers)) {
67 if (!array_key_exists(
'Connection', $headers)) {
68 $headers[
'Connection'] =
'close';
77 $encapsulated[
$type] = strlen($bodyData);
82 $encapsulated[
$type] = strlen($bodyData);
83 $bodyData .= dechex(strlen(
$data)) .
"\r\n";
91 $bodyData .=
"0\r\n\r\n";
92 } elseif (count($encapsulated) > 0) {
93 $encapsulated[
'null-body'] = strlen($bodyData);
95 if (count($encapsulated) > 0) {
96 $headers[
'Encapsulated'] =
'';
97 foreach ($encapsulated as
$section => $offset) {
98 $headers[
'Encapsulated'] .= $headers[
'Encapsulated'] ===
'' ?
'' :
', ';
99 $headers[
'Encapsulated'] .=
"{$section}={$offset}";
102 $request =
"{$method} icap://{$this->host}/{$service} ICAP/1.0\r\n";
103 foreach ($headers as $header => $value) {
104 $request .=
"{$header}: {$value}\r\n";
107 $request .= $bodyData;
120 socket_write($this->socket, $request);
121 while ($buffer = socket_read($this->socket, 2048)) {
125 }
catch(ErrorException
$e){
126 $this->log->warning(
"Cannot connect to icap://{$this->host}:{$this->port} (Socket error: " . $this->
getLastSocketError() .
")");
137 $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
139 if (!socket_connect($this->socket, $this->host, $this->port)) {
142 }
catch(ErrorException
$e){
155 return socket_last_error($this->socket);
163 socket_shutdown($this->socket);
164 socket_close($this->socket);
179 foreach (preg_split(
'/\r?\n/', $string) as $line) {
181 if (0 !== strpos($line,
'ICAP/')) {
184 $parts = preg_split(
'/ +/', $line, 3);
186 'icap' => isset($parts[0]) ? $parts[0] :
'',
187 'code' => isset($parts[1]) ? $parts[1] :
'',
188 'message' => isset($parts[2]) ? $parts[2] :
'',
195 $parts = preg_split(
'/: /', $line, 2);
196 if (isset($parts[0])) {
197 $response[
'headers'][$parts[0]] = isset($parts[1]) ? $parts[1] :
'';
200 $body = preg_split(
'/\r?\n\r?\n/', $string, 2);
201 if (isset($body[1])) {
203 if (array_key_exists(
'Encapsulated',
$response[
'headers'])) {
205 $params = preg_split(
'/, /',
$response[
'headers'][
'Encapsulated']);
206 if (count($params) > 0) {
207 foreach ($params as
$param) {
208 $parts = preg_split(
'/=/', $param);
209 if (count($parts) !== 2) {
212 $encapsulated[$parts[0]] = $parts[1];
215 foreach ($encapsulated as
$section => $offset) {
216 $data = substr($body[1], $offset);
224 $parts = preg_split(
'/\r?\n/',
$data, 2);
225 if (count($parts) === 2) {
__construct($a_scancommand, $a_cleancommand)
ilVirusScannerICap constructor.
Interface to the ClamAV virus protector.
respMod($service, $body=[], $headers=[])
Base class for the interface to an external virus scanner This class is abstract and needs to be exte...
__construct(Container $dic, ilPlugin $plugin)
getLastSocketError()
Get last error code from socket object.
reqMod($service, $body=[], $headers=[])
getRequest($method, $service, $body=[], $headers=[])