Skip to content

Commit 56080ad

Browse files
committed
apps/dav: add some OSX specific quirks.
1 parent 18c4761 commit 56080ad

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2023 Claus-Justus Heine
4+
*
5+
* @author Claus-Justus Heine <[email protected]>
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+
private $isMacOSDavAgent = false;
33+
34+
private $macOSVersion;
35+
36+
private $macOSAgent;
37+
38+
private $macOSAgentVersion;
39+
40+
/**
41+
* Sets up the plugin.
42+
*
43+
* This method is automatically called by the server class.
44+
*/
45+
public function initialize(Server $server)
46+
{
47+
$server->on('beforeMethod:*', [$this, 'beforeMethod'], 0);
48+
$server->on('report', [$this, 'report'], 0);
49+
}
50+
51+
/**
52+
* Triggered before any method is handled.
53+
*/
54+
public function beforeMethod(RequestInterface $request, ResponseInterface $response)
55+
{
56+
$userAgent = $request->getRawServerValue('HTTP_USER_AGENT');
57+
58+
// OSX agent string: macOS/13.2.1 (22D68) dataaccessd/1.0
59+
if (preg_match('|macOS/([0-9]+)\\.([0-9]+)\\.([0-9]+)\s+\((\w+)\)\s+([^/]+)/([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?$|i', $userAgent, $matches)) {
60+
$this->isMacOSDavAgent = true;
61+
$this->macOSVersion = [
62+
'major' => $matches[1],
63+
'minor' => $matches[2],
64+
'patch' => $matches[3],
65+
];
66+
$this->macOSAgent = $matches[5];
67+
$this->macOSAgentVersion = [
68+
'major' => $matches[6],
69+
'minor' => $matches[7] ?? null,
70+
'patch' => $matches[8] ?? null,
71+
];
72+
// \OCP\Util::writeLog('dav', 'OSX AGENT', \OCP\Util::INFO);
73+
}
74+
}
75+
76+
/**
77+
* This method handles HTTP REPORT requests.
78+
*
79+
* @param string $reportName
80+
* @param mixed $report
81+
* @param mixed $path
82+
*/
83+
public function report($reportName, $report, $path)
84+
{
85+
if ($this->isMacOSDavAgent && $reportName == '{DAV:}principal-property-search') {
86+
/** @var \Sabre\DAVACL\Xml\Request\PrincipalPropertySearchReport $report */
87+
$report->applyToPrincipalCollectionSet = true;
88+
}
89+
return true;
90+
}
91+
}

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)