Skip to content

Commit 11cc75a

Browse files
committed
apps/dav: add some OSX specific quirks.
Signed-off-by: Claus-Justus Heine <himself@claus-justus-heine.de>
1 parent 18c4761 commit 11cc75a

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2023 Claus-Justus Heine
4+
*
5+
* @author Claus-Justus Heine <himself@claus-justus-heine.de>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
namespace OCA\DAV\Connector\Sabre;
24+
25+
use Sabre\DAV\Server;
26+
use Sabre\DAV\ServerPlugin;
27+
use Sabre\HTTP\RequestInterface;
28+
use Sabre\HTTP\ResponseInterface;
29+
30+
class QuirksPlugin extends ServerPlugin {
31+
32+
/** @var bool */
33+
private $isMacOSDavAgent = false;
34+
35+
/** @psalm-var null|array{major: string, minor: string, patch: string} */
36+
private $macOSVersion = null;
37+
38+
/** @var null|string */
39+
private $macOSAgent = null;
40+
41+
/** @psalm-var null|array{major: string, minor: null|string, patch: null|string} */
42+
private $macOSAgentVersion = null;
43+
44+
/**
45+
* Sets up the plugin.
46+
*
47+
* This method is automatically called by the server class.
48+
*
49+
* @return void
50+
*/
51+
public function initialize(Server $server)
52+
{
53+
$server->on('beforeMethod:*', [$this, 'beforeMethod'], 0);
54+
$server->on('report', [$this, 'report'], 0);
55+
}
56+
57+
/**
58+
* Triggered before any method is handled.
59+
*
60+
* @return void
61+
*/
62+
public function beforeMethod(RequestInterface $request, ResponseInterface $response)
63+
{
64+
$userAgent = $request->getRawServerValue('HTTP_USER_AGENT') ?? 'unknown';
65+
66+
// OSX agent string: macOS/13.2.1 (22D68) dataaccessd/1.0
67+
if (preg_match('|macOS/([0-9]+)\\.([0-9]+)\\.([0-9]+)\s+\((\w+)\)\s+([^/]+)/([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?$|i', $userAgent, $matches)) {
68+
$this->isMacOSDavAgent = true;
69+
$this->macOSVersion = [
70+
'major' => $matches[1],
71+
'minor' => $matches[2],
72+
'patch' => $matches[3],
73+
];
74+
$this->macOSAgent = $matches[5];
75+
$this->macOSAgentVersion = [
76+
'major' => $matches[6],
77+
'minor' => $matches[7] ?? null,
78+
'patch' => $matches[8] ?? null,
79+
];
80+
// \OCP\Util::writeLog('dav', 'OSX AGENT', \OCP\Util::INFO);
81+
}
82+
}
83+
84+
/**
85+
* This method handles HTTP REPORT requests.
86+
*
87+
* @param string $reportName
88+
* @param mixed $report
89+
* @param mixed $path
90+
*
91+
* @return bool
92+
*/
93+
public function report($reportName, $report, $path)
94+
{
95+
if ($this->isMacOSDavAgent && $reportName == '{DAV:}principal-property-search') {
96+
/** @var \Sabre\DAVACL\Xml\Request\PrincipalPropertySearchReport $report */
97+
$report->applyToPrincipalCollectionSet = true;
98+
}
99+
return true;
100+
}
101+
}

apps/dav/lib/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public function __construct(IRequest $request, string $baseUri) {
110110
// Add maintenance plugin
111111
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
112112

113+
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\QuirksPlugin());
114+
113115
// Backends
114116
$authBackend = new Auth(
115117
\OC::$server->getSession(),

0 commit comments

Comments
 (0)