19 declare(strict_types=1);
29 public function __construct(
string $scan_command,
string $clean_command)
32 $this->host = IL_ICAP_HOST;
33 $this->port = (
int) IL_ICAP_PORT;
38 $request = $this->
getRequest(
'OPTIONS', $service);
46 public function getRequest(
string $method,
string $service, array $body = [], array $headers = []): string
48 if (!array_key_exists(
'Host', $headers)) {
51 if (!array_key_exists(
'User-Agent', $headers)) {
54 if (!array_key_exists(
'Connection', $headers)) {
55 $headers[
'Connection'] =
'close';
64 $encapsulated[
$type] = strlen($bodyData);
69 $encapsulated[
$type] = strlen($bodyData);
70 $bodyData .= dechex(strlen(
$data)) .
"\r\n";
78 $bodyData .=
"0\r\n\r\n";
79 } elseif (count($encapsulated) > 0) {
80 $encapsulated[
'null-body'] = strlen($bodyData);
82 if (count($encapsulated) > 0) {
83 $headers[
'Encapsulated'] =
'';
84 foreach ($encapsulated as $section => $offset) {
85 $headers[
'Encapsulated'] .= $headers[
'Encapsulated'] ===
'' ?
'' :
', ';
86 $headers[
'Encapsulated'] .=
"{$section}={$offset}";
89 $request =
"{$method} icap://{$this->host}/{$service} ICAP/1.0\r\n";
90 foreach ($headers as $header => $value) {
91 $request .=
"{$header}: {$value}\r\n";
94 $request .= $bodyData;
98 public function send(
string $request): string
103 socket_write($this->socket, $request);
104 while ($buffer = socket_read($this->socket, 2048)) {
109 $this->log->warning(
"Cannot connect to icap://{$this->host}:{$this->port} (Socket error: " . $this->
getLastSocketError() .
")");
116 $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
118 if (!socket_connect($this->socket, $this->host, $this->port)) {
130 return socket_last_error($this->socket);
135 socket_shutdown($this->socket);
136 socket_close($this->socket);
150 foreach (preg_split(
'/\r?\n/', $string) as $line) {
152 if (0 !== strpos($line,
'ICAP/')) {
155 $parts = preg_split(
'/ +/', $line, 3);
157 'icap' =>
$parts[0] ??
'',
158 'code' =>
$parts[1] ??
'',
159 'message' =>
$parts[2] ??
'',
166 $parts = explode(
": ", $line, 2);
171 $body = preg_split(
'/\r?\n\r?\n/', $string, 2);
172 if (isset($body[1])) {
174 if (array_key_exists(
'Encapsulated',
$response[
'headers'])) {
179 $parts = explode(
"=", $param);
180 if (count(
$parts) !== 2) {
183 $encapsulated[
$parts[0]] = $parts[1];
186 foreach ($encapsulated as $section => $offset) {
187 $data = substr($body[1], $offset);
191 $response[
'body'][$section] = preg_split(
'/\r?\n\r?\n/',
$data, 2)[0];
196 if (count(
$parts) === 2) {
210 public function respMod(
string $service, array $body = [], array $headers = []): array
212 $request = $this->
getRequest(
'RESPMOD', $service, $body, $headers);
220 public function reqMod(
string $service, array $body = [], array $headers = []): array
222 $request = $this->
getRequest(
'REQMOD', $service, $body, $headers);
getRequest(string $method, string $service, array $body=[], array $headers=[])
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
__construct(string $scan_command, string $clean_command)
respMod(string $service, array $body=[], array $headers=[])
reqMod(string $service, array $body=[], array $headers=[])
__construct(Container $dic, ilPlugin $plugin)
parseResponse(string $string)