Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/contactsinteraction/lib/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function getContentType(): ?string {
return 'text/vcard; charset=utf-8';
}

public function getVersion(): ?string {
return '3.0';
}

/**
* @inheritDoc
*/
Expand Down
5 changes: 5 additions & 0 deletions apps/dav/lib/CardDAV/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function getAddressbookId(): int {
return (int)$this->cardData['addressbookid'];
}

public function getVersion(): ?string {
preg_match('/^VERSION:([34])\.0/mi', $this->cardData['carddata'], $matches);
return isset($matches[1]) ? $matches[1] . '.0' : null;
}

public function getPrincipalUri(): string {
return $this->addressBookInfo['principaluri'];
}
Expand Down
81 changes: 81 additions & 0 deletions apps/dav/lib/CardDAV/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\DAV\CardDAV;

use OCA\DAV\CardDAV\Xml\Groups;
use Sabre\DAV\Exception\ReportNotSupported;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
Expand Down Expand Up @@ -58,4 +59,84 @@ public function propFind(PropFind $propFind, INode $node) {
});
}
}

/**
* This function handles the addressbook-query REPORT.
*
* This report is used by the client to filter an addressbook based on a
* complex query.
*
* @param \Sabre\CardDAV\Xml\Request\AddressBookQueryReport $report
*/
#[\Override]
protected function addressbookQueryReport($report) {
$depth = $this->server->getHTTPDepth(0);

if ($depth === 0) {
$candidateNodes = [
$this->server->tree->getNodeForPath($this->server->getRequestUri()),
];
if (!$candidateNodes[0] instanceof Card) {
throw new ReportNotSupported('The addressbook-query report is not supported on this url with Depth: 0');
}
} else {
$candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri());
}

$validNodes = [];
foreach ($candidateNodes as $node) {
if (!$node instanceof Card) {
continue;
}

if (!$this->validateFilters($node->get(), $report->filters, $report->test)) {
continue;
}

$validNodes[] = $node;

if ($report->limit && $report->limit <= count($validNodes)) {
// We hit the maximum number of items, we can stop now.
break;
}
}

$result = [];
foreach ($validNodes as $validNode) {
$contentType = $report->contentType;
// we theoretically support versions 3.0 and 4.0 so $vcardType should be dyncamic depending on the node
if ($validNode->getVersion()) {
$contentType .= '; version=' . $validNode->getVersion();
} elseif ($report->version) {
$contentType .= '; version=' . $report->version;
}
$vcardType = $this->negotiateVCard(
$contentType
);
if ($depth === 0) {
$href = $this->server->getRequestUri();
} else {
$href = $this->server->getRequestUri() . '/' . $validNode->getName();
}

/** @psalm-suppress DeprecatedMethod */
[$props] = $this->server->getPropertiesForPath($href, $report->properties, 0);

if (isset($props[200]['{' . self::NS_CARDDAV . '}address-data'])) {
$props[200]['{' . self::NS_CARDDAV . '}address-data'] = $this->convertVCard(
$props[200]['{' . self::NS_CARDDAV . '}address-data'],
$vcardType,
$report->addressDataProperties
);
}
$result[] = $props;
}

$prefer = $this->server->getHTTPPrefer();

$this->server->httpResponse->setStatus(207);
$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
$this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
$this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
}
}
Loading