- Модуль: dav
- Путь к файлу: ~/bitrix/modules/dav/classes/general/webdav.php
- Класс: CDavWebDav
- Вызов: CDavWebDav::LOCKWrapper
protected function LOCKWrapper()
{
/** @var CDavRequest $request */
$request = $this->request;
$response = $this->response;
$httpTimeout = $request->GetParameter("HTTP_TIMEOUT");
if (!is_null($httpTimeout))
{
$httpTimeout = explode(",", $httpTimeout);
$httpTimeout = $httpTimeout[0];
}
$contentLength = $request->GetParameter('CONTENT_LENGTH');
$httpIf = $request->GetParameter('HTTP_IF');
if (empty($contentLength) && !empty($httpIf))
{
if (!$this->CheckLockStatus($request->GetPath()))
{
$response->SetHttpStatus("423 Locked");
return;
}
$locktoken = mb_substr($httpIf, 2, -2);
$updateLock = true;
$owner = "id:".$request->GetPrincipal()->Id();
$scope = "exclusive";
$type = "write";
}
else
{
try
{
$requestDocument = $request->GetXmlDocument();
}
catch (CDavXMLParsingException $e)
{
$response->GenerateError("400 Error", $e->getMessage());
return;
}
catch (Exception $e)
{
$response->SetHttpStatus("400 Error");
return;
}
$lockscopes = $requestDocument->GetPath('/*/DAV::lockscope/*');
$lockscope = (is_array($lockscopes) && !empty($lockscopes)) ? $lockscopes[0]->GetTag() : "exclusive";
if (!$this->CheckLockStatus($request->GetPath(), $lockscope !== "shared"))
{
$response->SetHttpStatus("423 Locked");
return;
}
$locktoken = $this->getNewLockToken();
$updateLock = false;
$owners = $requestDocument->GetPath('/*/DAV::owner/*');
$owner = is_array($owners) && !empty($owners) ? $owners[0]->GetContent() : "";
$scope = $lockscope;
$types = $requestDocument->GetPath('/*/DAV::locktype/*');
$type = (is_array($types) && !empty($types)) ? $types[0]->GetTag() : "write";
}
$stat = $this->LOCK($locktoken, $httpTimeout, $owner, $scope, $type, $updateLock);
if (is_bool($stat))
{
$httpStat = $stat ? "200 OK" : "423 Locked";
}
else
{
$httpStat = $stat;
}
$response->SetHttpStatus($httpStat);
if (mb_strpos($httpStat, 2) === 0)
{
// 2xx states are ok
if (!is_null($httpTimeout))
{
// if (is_numeric($httpTimeout))
// {
// more than a million is considered an absolute timestamp less is more likely a relative value
if ($httpTimeout > 1000000)
{
$timeout = "Second-" . ($httpTimeout - time());
}
else
{
$timeout = "Second-" . $httpTimeout;
}
// }
// else
// {
// $timeout = $httpTimeout;
// }
}
else
{
$timeout = "Infinite";
}
$response->AddHeader('Content-Type: text/xml; charset="utf-8"');
$response->AddHeader("Lock-Token: <".$locktoken.">");
$response->AddLine("");
$response->AddLine(" ");
$response->AddLine(" ");
$response->AddLine(" ");
$response->AddLine(" ");
$response->AddLine(" ".$request->GetDepth()."");
$response->AddLine(" ".$owner."");
$response->AddLine(" ".$timeout."");
$response->AddLine(" ".$locktoken."");
$response->AddLine(" ");
$response->AddLine(" ");
$response->AddLine("");
}
}