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 (count($arResources) == 0) { $response->SetHttpStatus("404 Not Found"); return; } } elseif (is_string($retVal)) { $message = ""; if (substr($retVal, 0, 3) == '501') { $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: " . join(",", $dav)); $response->AddHeader('Content-Type: text/xml; charset="utf-8"'); $response->AddLine("<D:multistatus xmlns:D=\"DAV:\"" . ($this instanceof CDavWebDavServer ? " xmlns:Office=\"urn:schemas-microsoft-com:office:office\" xmlns:Repl=\"http://schemas.microsoft.com/repl/\" xmlns:Z=\"urn:schemas-microsoft-com:\"" : "") . ">"); $bRequestedAllProp = count($requestDocument->GetPath('/*/DAV::allprop')) > 0; if ($this instanceof CDavWebDavServer) { $bRequestedAllProp = true; } $bRequestedPropName = count($requestDocument->GetPath('/*/DAV::propname')) > 0; $arRequestedPropsList = array(); if (!$bRequestedAllProp) { $ar = $requestDocument->GetPath('/*/DAV::prop/*'); foreach ($ar as $pw) { $arRequestedPropsList[] = array("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(" <D:response %s>", $xmlnsDefs); $href = $this->UrlEncode($response->Encode(rtrim($request->GetBaseUri(), '/') . "/" . ltrim($resource->GetPath(), '/'))); $response->AddLine(" <D:href>%s</D:href>", $href); if (count($arPropStat["200"]) > 0) { $response->AddLine(" <D:propstat>"); $response->AddLine(" <D:prop>"); foreach ($arPropStat["200"] as &$p) { CDavResource::RenderProperty($p, $xmlnsHash, $response, $request); } $response->AddLine(" </D:prop>"); $response->AddLine(" <D:status>HTTP/1.1 200 OK</D:status>"); $response->AddLine(" </D:propstat>"); } if (count($arPropStat["404"]) > 0) { $response->AddLine(" <D:propstat>"); $response->AddLine(" <D:prop>"); foreach ($arPropStat["404"] as &$p) { CDavResource::RenderProperty($p, $xmlnsHash, $response, $request); } $response->AddLine(" </D:prop>"); $response->AddLine(" <D:status>HTTP/1.1 404 Not Found</D:status>"); $response->AddLine(" </D:propstat>"); } $response->AddLine(" </D:response>"); } $response->AddLine("</D:multistatus>"); }