• Модуль: dav
  • Путь к файлу: ~/bitrix/modules/dav/classes/general/webdav.php
  • Класс: CDavWebDav
  • Вызов: CDavWebDav::PROPFINDWrapper
protected function PROPFINDWrapper($handler = 'PROPFIND')
{
	/** @var CDavRequest $request */
	$request = $this->request;
	$response = $this->response;

	try
	{
		$requestDocument = $request->GetXmlDocument();
	}
	catch (CDavXMLParsingException $e)
	{
		$response->GenerateError("400 Error", $e->getMessage());
		return;
	}
	catch (Exception $e)
	{
		$response->SetHttpStatus("400 Error");
		return;
	}

	$arResources = array();

	$retVal = $this->$handler($arResources);

	if ($retVal === false)
	{
		if (method_exists($this, "CheckLock"))
		{
			$arLock = $this->CheckLock($request->GetPath());
			if (is_array($arLock) && count($arLock) > 0)
			{
				$resource = new CDavResource();
				$resource->ExtractFromLock($request->GetPath(), $arLock);
				$arResources[] = $resource;
			}
		}

		if (empty($arResources))
		{
			$response->SetHttpStatus("404 Not Found");
			return;
		}
	}
	elseif (is_string($retVal))
	{
		$message = "";
		if (mb_strpos($retVal, '501') === 0)
		{
			$message .= "The requested feature is not supported by this server.n";
		}
		$response->GenerateError($retVal, $message);

		return;
	}

	$response->SetHttpStatus('207 Multi-Status');

	$dav = array(1);
	$allow = false;
	if (method_exists($this, 'OPTIONS'))
	{
		$this->OPTIONS($dav, $allow);
	}

	$response->AddHeader("DAV: ".implode(",", $dav));
	$response->AddHeader('Content-Type: text/xml; charset="utf-8"');

	$response->AddLine("");

	$bRequestedAllProp = (count($requestDocument->GetPath('/*/DAV::allprop')) > 0);
	if ($this instanceof CDavWebDavServer)
	{
		$bRequestedAllProp = true;
	}

	$arRequestedPropsList = array();
	if (!$bRequestedAllProp)
	{
		$ar = $requestDocument->GetPath('/*/DAV::prop/*');
		foreach ($ar as $pw)
		{
			$arRequestedPropsList[] = ["xmlns" => $pw->GetXmlNS(), "tagname" => $pw->GetTag()];
		}
	}

	foreach ($arResources as $resource)
	{
		/** @var CDavResource $resource */
		$arResourceProps = $resource->GetProperties();

		$arRequestedProps = &$arRequestedPropsList;
		if ($bRequestedAllProp)
		{
			$arRequestedProps = &$arResourceProps;
		}

		$xmlnsHash = array('DAV:' => 'D');
		$xmlnsDefs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';

		$arPropStat = array("200" => array(), "404" => array());

		foreach ($arRequestedProps as &$requestedProp)
		{
			$bFound = false;

			foreach ($arResourceProps as &$prop)
			{
				if ($requestedProp["tagname"] == $prop["tagname"] && $requestedProp["xmlns"] == $prop["xmlns"])
				{
					$arPropStat["200"][] = &$prop;
					$bFound = true;
					break;
				}
			}

			if (!$bFound)
			{
				if ($requestedProp["xmlns"] === "DAV:" && $requestedProp["tagname"] === "lockdiscovery")
				{
					$arPropStat["200"][] = CDavResource::MakeProp("lockdiscovery", $this->LockDiscovery($resource->GetPath()), "DAV:");
					$bFound = true;
				}
				elseif ($request->GetParameter('HTTP_BRIEF') !== 't')
				{
					$arPropStat["404"][] = CDavResource::MakeProp($requestedProp["tagname"], "", $requestedProp["xmlns"]);
				}
			}

			if (!empty($requestedProp["xmlns"]) && ($bFound || $request->GetParameter('HTTP_BRIEF') !== 't'))
			{
				$xmlns = $requestedProp["xmlns"];
				if (!isset($xmlnsHash[$xmlns]))
				{
					$n = "ns".(count($xmlnsHash) + 1);
					$xmlnsHash[$xmlns] = $n;
					$xmlnsDefs .= " xmlns:$n="$xmlns"";
				}
			}
		}

		$response->AddLine(" ", $xmlnsDefs);

		$href = $this->UrlEncode($response->Encode(rtrim($request->GetBaseUri(), '/')."/".ltrim($resource->GetPath(), '/')));
		$response->AddLine("  %s", $href);

		if (count($arPropStat["200"]) > 0)
		{
			$response->AddLine("   ");
			$response->AddLine("    ");

			foreach ($arPropStat["200"] as &$p)
			{
				CDavResource::RenderProperty($p, $xmlnsHash, $response, $request);
			}

			$response->AddLine("    ");
			$response->AddLine("    HTTP/1.1 200 OK");
			$response->AddLine("   ");
		}

		if (count($arPropStat["404"]) > 0)
		{
			$response->AddLine("   ");
			$response->AddLine("    ");

			foreach ($arPropStat["404"] as &$p)
			{
				CDavResource::RenderProperty($p, $xmlnsHash, $response, $request);
			}

			$response->AddLine("    ");
			$response->AddLine("    HTTP/1.1 404 Not Found");
			$response->AddLine("   ");
		}

		$response->AddLine(" ");
	}

	$response->AddLine("");
}