|
| 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 | +} |
0 commit comments