From dd3f5daf592b1440938e4726bb7c20c7f972588f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 12 Jul 2022 17:42:58 +0200 Subject: [PATCH] Bump sabre/dav to 4.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- composer.json | 2 +- composer.lock | 52 ++++---- composer/autoload_classmap.php | 1 + composer/autoload_static.php | 1 + composer/installed.json | 56 ++++----- composer/installed.php | 22 ++-- sabre/dav/README.md | 21 ++-- sabre/dav/composer.json | 2 +- sabre/dav/lib/CalDAV/Backend/PDO.php | 51 +++++--- sabre/dav/lib/CalDAV/Calendar.php | 13 +- .../dav/lib/DAV/Auth/Backend/PDOBasicAuth.php | 114 ++++++++++++++++++ sabre/dav/lib/DAV/CorePlugin.php | 5 + sabre/dav/lib/DAV/StringUtil.php | 6 +- sabre/dav/lib/DAV/Sync/Plugin.php | 13 +- sabre/dav/lib/DAV/Tree.php | 2 +- sabre/dav/lib/DAV/Version.php | 2 +- sabre/http/CHANGELOG.md | 10 ++ sabre/http/lib/Sapi.php | 58 ++++----- sabre/http/lib/Version.php | 2 +- sabre/http/lib/functions.php | 6 +- sabre/vobject/lib/Component.php | 2 +- sabre/vobject/lib/Component/VCard.php | 5 + .../lib/Property/ICalendar/CalAddress.php | 6 +- sabre/vobject/lib/StringUtil.php | 18 +-- sabre/vobject/lib/Version.php | 2 +- 25 files changed, 314 insertions(+), 158 deletions(-) create mode 100644 sabre/dav/lib/DAV/Auth/Backend/PDOBasicAuth.php diff --git a/composer.json b/composer.json index 289f1193d..e291fb3af 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "psr/container": "^1.1.1", "psr/event-dispatcher": "^1.0", "punic/punic": "^1.6", - "sabre/dav": "^4.2.1", + "sabre/dav": "^4.4.0", "scssphp/scssphp": "^1.8.1", "stecman/symfony-console-completion": "^0.11.0", "swiftmailer/swiftmailer": "^6.0", diff --git a/composer.lock b/composer.lock index 4c76909aa..2e4479b4a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2771f5d423707681693d725b709d0ad8", + "content-hash": "62a9ea5f04f28df33dfdeea90ed8bcdb", "packages": [ { "name": "aws/aws-sdk-php", @@ -3660,16 +3660,16 @@ }, { "name": "sabre/dav", - "version": "4.2.1", + "version": "4.4.0", "source": { "type": "git", "url": "https://github.com/sabre-io/dav.git", - "reference": "5e651f9ddc2b05745f5b28cd697c8e8c6a0b6146" + "reference": "b65362abc926520eda2c57e219f022a6c288069d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sabre-io/dav/zipball/5e651f9ddc2b05745f5b28cd697c8e8c6a0b6146", - "reference": "5e651f9ddc2b05745f5b28cd697c8e8c6a0b6146", + "url": "https://api.github.com/repos/sabre-io/dav/zipball/b65362abc926520eda2c57e219f022a6c288069d", + "reference": "b65362abc926520eda2c57e219f022a6c288069d", "shasum": "" }, "require": { @@ -3684,7 +3684,7 @@ "ext-spl": "*", "lib-libxml": ">=2.7.0", "php": "^7.1.0 || ^8.0", - "psr/log": "^1.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", "sabre/event": "^5.0", "sabre/http": "^5.0.5", "sabre/uri": "^2.0", @@ -3711,8 +3711,8 @@ "autoload": { "psr-4": { "Sabre\\DAV\\": "lib/DAV/", - "Sabre\\DAVACL\\": "lib/DAVACL/", "Sabre\\CalDAV\\": "lib/CalDAV/", + "Sabre\\DAVACL\\": "lib/DAVACL/", "Sabre\\CardDAV\\": "lib/CardDAV/" } }, @@ -3742,7 +3742,7 @@ "issues": "https://github.com/sabre-io/dav/issues", "source": "https://github.com/fruux/sabre-dav" }, - "time": "2021-11-30T13:53:16+00:00" + "time": "2022-06-27T09:07:55+00:00" }, { "name": "sabre/event", @@ -3768,14 +3768,14 @@ }, "type": "library", "autoload": { - "psr-4": { - "Sabre\\Event\\": "lib/" - }, "files": [ "lib/coroutine.php", "lib/Loop/functions.php", "lib/Promise/functions.php" - ] + ], + "psr-4": { + "Sabre\\Event\\": "lib/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3812,16 +3812,16 @@ }, { "name": "sabre/http", - "version": "5.1.3", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sabre-io/http.git", - "reference": "315f592adfcba8aeb73c2fd64285205747acbbd7" + "reference": "164725c2d2e248384e5b6115510c545e9c47cff9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sabre-io/http/zipball/315f592adfcba8aeb73c2fd64285205747acbbd7", - "reference": "315f592adfcba8aeb73c2fd64285205747acbbd7", + "url": "https://api.github.com/repos/sabre-io/http/zipball/164725c2d2e248384e5b6115510c545e9c47cff9", + "reference": "164725c2d2e248384e5b6115510c545e9c47cff9", "shasum": "" }, "require": { @@ -3871,7 +3871,7 @@ "issues": "https://github.com/sabre-io/http/issues", "source": "https://github.com/fruux/sabre-http" }, - "time": "2021-11-04T07:02:36+00:00" + "time": "2022-07-09T08:38:22+00:00" }, { "name": "sabre/uri", @@ -3932,16 +3932,16 @@ }, { "name": "sabre/vobject", - "version": "4.4.1", + "version": "4.4.2", "source": { "type": "git", "url": "https://github.com/sabre-io/vobject.git", - "reference": "06feff370141fd3118609f808e86d9315864bf14" + "reference": "b8a44ea1610d9b7012e42a7ff6f1cb66f0b757dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sabre-io/vobject/zipball/06feff370141fd3118609f808e86d9315864bf14", - "reference": "06feff370141fd3118609f808e86d9315864bf14", + "url": "https://api.github.com/repos/sabre-io/vobject/zipball/b8a44ea1610d9b7012e42a7ff6f1cb66f0b757dd", + "reference": "b8a44ea1610d9b7012e42a7ff6f1cb66f0b757dd", "shasum": "" }, "require": { @@ -4032,7 +4032,7 @@ "issues": "https://github.com/sabre-io/vobject/issues", "source": "https://github.com/fruux/sabre-vobject" }, - "time": "2021-12-07T09:45:33+00:00" + "time": "2022-06-24T11:36:21+00:00" }, { "name": "sabre/xml", @@ -4063,13 +4063,13 @@ }, "type": "library", "autoload": { - "psr-4": { - "Sabre\\Xml\\": "lib/" - }, "files": [ "lib/Deserializer/functions.php", "lib/Serializer/functions.php" - ] + ], + "psr-4": { + "Sabre\\Xml\\": "lib/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ diff --git a/composer/autoload_classmap.php b/composer/autoload_classmap.php index 170ea4f95..d67ffe5bd 100644 --- a/composer/autoload_classmap.php +++ b/composer/autoload_classmap.php @@ -2391,6 +2391,7 @@ 'Sabre\\DAV\\Auth\\Backend\\File' => $vendorDir . '/sabre/dav/lib/DAV/Auth/Backend/File.php', 'Sabre\\DAV\\Auth\\Backend\\IMAP' => $vendorDir . '/sabre/dav/lib/DAV/Auth/Backend/IMAP.php', 'Sabre\\DAV\\Auth\\Backend\\PDO' => $vendorDir . '/sabre/dav/lib/DAV/Auth/Backend/PDO.php', + 'Sabre\\DAV\\Auth\\Backend\\PDOBasicAuth' => $vendorDir . '/sabre/dav/lib/DAV/Auth/Backend/PDOBasicAuth.php', 'Sabre\\DAV\\Auth\\Plugin' => $vendorDir . '/sabre/dav/lib/DAV/Auth/Plugin.php', 'Sabre\\DAV\\Browser\\GuessContentType' => $vendorDir . '/sabre/dav/lib/DAV/Browser/GuessContentType.php', 'Sabre\\DAV\\Browser\\HtmlOutput' => $vendorDir . '/sabre/dav/lib/DAV/Browser/HtmlOutput.php', diff --git a/composer/autoload_static.php b/composer/autoload_static.php index b375a6d90..a195c71d0 100644 --- a/composer/autoload_static.php +++ b/composer/autoload_static.php @@ -3032,6 +3032,7 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652 'Sabre\\DAV\\Auth\\Backend\\File' => __DIR__ . '/..' . '/sabre/dav/lib/DAV/Auth/Backend/File.php', 'Sabre\\DAV\\Auth\\Backend\\IMAP' => __DIR__ . '/..' . '/sabre/dav/lib/DAV/Auth/Backend/IMAP.php', 'Sabre\\DAV\\Auth\\Backend\\PDO' => __DIR__ . '/..' . '/sabre/dav/lib/DAV/Auth/Backend/PDO.php', + 'Sabre\\DAV\\Auth\\Backend\\PDOBasicAuth' => __DIR__ . '/..' . '/sabre/dav/lib/DAV/Auth/Backend/PDOBasicAuth.php', 'Sabre\\DAV\\Auth\\Plugin' => __DIR__ . '/..' . '/sabre/dav/lib/DAV/Auth/Plugin.php', 'Sabre\\DAV\\Browser\\GuessContentType' => __DIR__ . '/..' . '/sabre/dav/lib/DAV/Browser/GuessContentType.php', 'Sabre\\DAV\\Browser\\HtmlOutput' => __DIR__ . '/..' . '/sabre/dav/lib/DAV/Browser/HtmlOutput.php', diff --git a/composer/installed.json b/composer/installed.json index 88fb01771..95b1b4c85 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -3822,17 +3822,17 @@ }, { "name": "sabre/dav", - "version": "4.2.1", - "version_normalized": "4.2.1.0", + "version": "4.4.0", + "version_normalized": "4.4.0.0", "source": { "type": "git", "url": "https://github.com/sabre-io/dav.git", - "reference": "5e651f9ddc2b05745f5b28cd697c8e8c6a0b6146" + "reference": "b65362abc926520eda2c57e219f022a6c288069d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sabre-io/dav/zipball/5e651f9ddc2b05745f5b28cd697c8e8c6a0b6146", - "reference": "5e651f9ddc2b05745f5b28cd697c8e8c6a0b6146", + "url": "https://api.github.com/repos/sabre-io/dav/zipball/b65362abc926520eda2c57e219f022a6c288069d", + "reference": "b65362abc926520eda2c57e219f022a6c288069d", "shasum": "" }, "require": { @@ -3847,7 +3847,7 @@ "ext-spl": "*", "lib-libxml": ">=2.7.0", "php": "^7.1.0 || ^8.0", - "psr/log": "^1.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", "sabre/event": "^5.0", "sabre/http": "^5.0.5", "sabre/uri": "^2.0", @@ -3866,7 +3866,7 @@ "ext-imap": "*", "ext-pdo": "*" }, - "time": "2021-11-30T13:53:16+00:00", + "time": "2022-06-27T09:07:55+00:00", "bin": [ "bin/sabredav", "bin/naturalselection" @@ -3876,8 +3876,8 @@ "autoload": { "psr-4": { "Sabre\\DAV\\": "lib/DAV/", - "Sabre\\DAVACL\\": "lib/DAVACL/", "Sabre\\CalDAV\\": "lib/CalDAV/", + "Sabre\\DAVACL\\": "lib/DAVACL/", "Sabre\\CardDAV\\": "lib/CardDAV/" } }, @@ -3936,14 +3936,14 @@ "type": "library", "installation-source": "dist", "autoload": { - "psr-4": { - "Sabre\\Event\\": "lib/" - }, "files": [ "lib/coroutine.php", "lib/Loop/functions.php", "lib/Promise/functions.php" - ] + ], + "psr-4": { + "Sabre\\Event\\": "lib/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3980,17 +3980,17 @@ }, { "name": "sabre/http", - "version": "5.1.3", - "version_normalized": "5.1.3.0", + "version": "5.1.5", + "version_normalized": "5.1.5.0", "source": { "type": "git", "url": "https://github.com/sabre-io/http.git", - "reference": "315f592adfcba8aeb73c2fd64285205747acbbd7" + "reference": "164725c2d2e248384e5b6115510c545e9c47cff9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sabre-io/http/zipball/315f592adfcba8aeb73c2fd64285205747acbbd7", - "reference": "315f592adfcba8aeb73c2fd64285205747acbbd7", + "url": "https://api.github.com/repos/sabre-io/http/zipball/164725c2d2e248384e5b6115510c545e9c47cff9", + "reference": "164725c2d2e248384e5b6115510c545e9c47cff9", "shasum": "" }, "require": { @@ -4009,7 +4009,7 @@ "suggest": { "ext-curl": " to make http requests with the Client class" }, - "time": "2021-11-04T07:02:36+00:00", + "time": "2022-07-09T08:38:22+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -4106,17 +4106,17 @@ }, { "name": "sabre/vobject", - "version": "4.4.1", - "version_normalized": "4.4.1.0", + "version": "4.4.2", + "version_normalized": "4.4.2.0", "source": { "type": "git", "url": "https://github.com/sabre-io/vobject.git", - "reference": "06feff370141fd3118609f808e86d9315864bf14" + "reference": "b8a44ea1610d9b7012e42a7ff6f1cb66f0b757dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sabre-io/vobject/zipball/06feff370141fd3118609f808e86d9315864bf14", - "reference": "06feff370141fd3118609f808e86d9315864bf14", + "url": "https://api.github.com/repos/sabre-io/vobject/zipball/b8a44ea1610d9b7012e42a7ff6f1cb66f0b757dd", + "reference": "b8a44ea1610d9b7012e42a7ff6f1cb66f0b757dd", "shasum": "" }, "require": { @@ -4133,7 +4133,7 @@ "suggest": { "hoa/bench": "If you would like to run the benchmark scripts" }, - "time": "2021-12-07T09:45:33+00:00", + "time": "2022-06-24T11:36:21+00:00", "bin": [ "bin/vobject", "bin/generate_vcards" @@ -4243,13 +4243,13 @@ "type": "library", "installation-source": "dist", "autoload": { - "psr-4": { - "Sabre\\Xml\\": "lib/" - }, "files": [ "lib/Deserializer/functions.php", "lib/Serializer/functions.php" - ] + ], + "psr-4": { + "Sabre\\Xml\\": "lib/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ diff --git a/composer/installed.php b/composer/installed.php index 4de987856..58c14fb1d 100644 --- a/composer/installed.php +++ b/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'nextcloud/3rdparty', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '4df515095bbbcca750a6d5e4c0d50fe1d6960b62', + 'reference' => '2d3ffebfcfb22af6d999d575b53e8f41cdfb4e9f', 'type' => 'library', 'install_path' => __DIR__ . '/../', 'aliases' => array(), @@ -301,7 +301,7 @@ 'nextcloud/3rdparty' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '4df515095bbbcca750a6d5e4c0d50fe1d6960b62', + 'reference' => '2d3ffebfcfb22af6d999d575b53e8f41cdfb4e9f', 'type' => 'library', 'install_path' => __DIR__ . '/../', 'aliases' => array(), @@ -590,9 +590,9 @@ ), ), 'sabre/dav' => array( - 'pretty_version' => '4.2.1', - 'version' => '4.2.1.0', - 'reference' => '5e651f9ddc2b05745f5b28cd697c8e8c6a0b6146', + 'pretty_version' => '4.4.0', + 'version' => '4.4.0.0', + 'reference' => 'b65362abc926520eda2c57e219f022a6c288069d', 'type' => 'library', 'install_path' => __DIR__ . '/../sabre/dav', 'aliases' => array(), @@ -608,9 +608,9 @@ 'dev_requirement' => false, ), 'sabre/http' => array( - 'pretty_version' => '5.1.3', - 'version' => '5.1.3.0', - 'reference' => '315f592adfcba8aeb73c2fd64285205747acbbd7', + 'pretty_version' => '5.1.5', + 'version' => '5.1.5.0', + 'reference' => '164725c2d2e248384e5b6115510c545e9c47cff9', 'type' => 'library', 'install_path' => __DIR__ . '/../sabre/http', 'aliases' => array(), @@ -626,9 +626,9 @@ 'dev_requirement' => false, ), 'sabre/vobject' => array( - 'pretty_version' => '4.4.1', - 'version' => '4.4.1.0', - 'reference' => '06feff370141fd3118609f808e86d9315864bf14', + 'pretty_version' => '4.4.2', + 'version' => '4.4.2.0', + 'reference' => 'b8a44ea1610d9b7012e42a7ff6f1cb66f0b757dd', 'type' => 'library', 'install_path' => __DIR__ . '/../sabre/vobject', 'aliases' => array(), diff --git a/sabre/dav/README.md b/sabre/dav/README.md index acdb1e03c..32ca1c3fa 100644 --- a/sabre/dav/README.md +++ b/sabre/dav/README.md @@ -14,16 +14,17 @@ http://sabre.io/ Build status ------------ -| branch | status | minimum PHP version | -| ------------ | ------ | ------------------- | -| master | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=master)](https://travis-ci.org/sabre-io/dav) | PHP 7.1 | -| 3.1 | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=3.0)](https://travis-ci.org/sabre-io/dav) | PHP 5.5 | -| 3.0 | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=3.0)](https://travis-ci.org/sabre-io/dav) | PHP 5.4 | -| 2.1 | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=2.1)](https://travis-ci.org/sabre-io/dav) | PHP 5.4 | -| 2.0 | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=2.0)](https://travis-ci.org/sabre-io/dav) | PHP 5.4 | -| 1.8 | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=1.8)](https://travis-ci.org/sabre-io/dav) | PHP 5.3 | -| 1.7 | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=1.7)](https://travis-ci.org/sabre-io/dav) | PHP 5.3 | -| 1.6 | [![Build Status](https://travis-ci.org/sabre-io/dav.svg?branch=1.6)](https://travis-ci.org/sabre-io/dav) | PHP 5.3 | +| branch | status | PHP version | +|------------|---------------------------------------------------------------------------|--------------------| +| master 4.* | ![CI](https://github.com/sabre-io/dav/actions/workflows/ci.yml/badge.svg) | PHP 7.1 up, 8.0 up | +| 3.2 | unmaintained | PHP 5.5 to 7.1 | +| 3.1 | unmaintained | PHP 5.5 | +| 3.0 | unmaintained | PHP 5.4 | +| 2.1 | unmaintained | PHP 5.4 | +| 2.0 | unmaintained | PHP 5.4 | +| 1.8 | unmaintained | PHP 5.3 | +| 1.7 | unmaintained | PHP 5.3 | +| 1.6 | unmaintained | PHP 5.3 | Documentation ------------- diff --git a/sabre/dav/composer.json b/sabre/dav/composer.json index 7c9596d21..5f0a44d66 100644 --- a/sabre/dav/composer.json +++ b/sabre/dav/composer.json @@ -29,7 +29,7 @@ "ext-date" : "*", "ext-iconv" : "*", "lib-libxml" : ">=2.7.0", - "psr/log": "^1.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", "ext-json": "*" }, "require-dev" : { diff --git a/sabre/dav/lib/CalDAV/Backend/PDO.php b/sabre/dav/lib/CalDAV/Backend/PDO.php index 0d5df3968..2f48ab982 100644 --- a/sabre/dav/lib/CalDAV/Backend/PDO.php +++ b/sabre/dav/lib/CalDAV/Backend/PDO.php @@ -948,42 +948,46 @@ public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limi } list($calendarId, $instanceId) = $calendarId; - // Current synctoken - $stmt = $this->pdo->prepare('SELECT synctoken FROM '.$this->calendarTableName.' WHERE id = ?'); - $stmt->execute([$calendarId]); - $currentToken = $stmt->fetchColumn(0); - - if (is_null($currentToken)) { - return null; - } - $result = [ - 'syncToken' => $currentToken, 'added' => [], 'modified' => [], 'deleted' => [], ]; if ($syncToken) { - $query = 'SELECT uri, operation FROM '.$this->calendarChangesTableName.' WHERE synctoken >= ? AND synctoken < ? AND calendarid = ? ORDER BY synctoken'; + $query = 'SELECT uri, operation, synctoken FROM '.$this->calendarChangesTableName.' WHERE synctoken >= ? AND calendarid = ? ORDER BY synctoken'; if ($limit > 0) { - $query .= ' LIMIT '.(int) $limit; + // Fetch one more raw to detect result truncation + $query .= ' LIMIT '.((int) $limit + 1); } // Fetching all changes $stmt = $this->pdo->prepare($query); - $stmt->execute([$syncToken, $currentToken, $calendarId]); + $stmt->execute([$syncToken, $calendarId]); $changes = []; // This loop ensures that any duplicates are overwritten, only the // last change on a node is relevant. while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $changes[$row['uri']] = $row['operation']; + $changes[$row['uri']] = $row; } + $currentToken = null; + $result_count = 0; foreach ($changes as $uri => $operation) { - switch ($operation) { + if (!is_null($limit) && $result_count >= $limit) { + $result['result_truncated'] = true; + break; + } + + if (null === $currentToken || $currentToken < $operation['synctoken'] + 1) { + // SyncToken in CalDAV perspective is consistently the next number of the last synced change event in this class. + $currentToken = $operation['synctoken'] + 1; + } + + ++$result_count; + switch ($operation['operation']) { case 1: $result['added'][] = $uri; break; @@ -995,7 +999,24 @@ public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limi break; } } + + if (!is_null($currentToken)) { + $result['syncToken'] = $currentToken; + } else { + // This means returned value is equivalent to syncToken + $result['syncToken'] = $syncToken; + } } else { + // Current synctoken + $stmt = $this->pdo->prepare('SELECT synctoken FROM '.$this->calendarTableName.' WHERE id = ?'); + $stmt->execute([$calendarId]); + $currentToken = $stmt->fetchColumn(0); + + if (is_null($currentToken)) { + return null; + } + $result['syncToken'] = $currentToken; + // No synctoken supplied, this is the initial sync. $query = 'SELECT uri FROM '.$this->calendarObjectTableName.' WHERE calendarid = ?'; $stmt = $this->pdo->prepare($query); diff --git a/sabre/dav/lib/CalDAV/Calendar.php b/sabre/dav/lib/CalDAV/Calendar.php index 9f32e702a..6e989314d 100644 --- a/sabre/dav/lib/CalDAV/Calendar.php +++ b/sabre/dav/lib/CalDAV/Calendar.php @@ -396,7 +396,8 @@ public function getSyncToken() * 'deleted' => [ * 'foo.php.bak', * 'old.txt' - * ] + * ], + * 'result_truncated' : true * ]; * * The syncToken property should reflect the *current* syncToken of the @@ -406,6 +407,9 @@ public function getSyncToken() * If the syncToken is specified as null, this is an initial sync, and all * members should be reported. * + * If result is truncated due to server limitation or limit by client, + * set result_truncated to true, otherwise set to false or do not add the key. + * * The modified property is an array of nodenames that have changed since * the last token. * @@ -422,12 +426,17 @@ public function getSyncToken() * should be treated as infinite. * * If the limit (infinite or not) is higher than you're willing to return, - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. + * the result should be truncated to fit the limit. + * Note that even when the result is truncated, syncToken must be consistent + * with the truncated result, not the result before truncation. + * (See RFC6578 Section 3.6 for detail) * * If the syncToken is expired (due to data cleanup) or unknown, you must * return null. * * The limit is 'suggestive'. You are free to ignore it. + * TODO: RFC6578 Setion 3.7 says that the server must fail when the server + * cannot truncate according to the limit, so it may not be just suggestive. * * @param string $syncToken * @param int $syncLevel diff --git a/sabre/dav/lib/DAV/Auth/Backend/PDOBasicAuth.php b/sabre/dav/lib/DAV/Auth/Backend/PDOBasicAuth.php new file mode 100644 index 000000000..39324e4db --- /dev/null +++ b/sabre/dav/lib/DAV/Auth/Backend/PDOBasicAuth.php @@ -0,0 +1,114 @@ +pdo = $pdo; + if (isset($options['tableName'])) { + $this->tableName = $options['tableName']; + } else { + $this->tableName = 'users'; + } + if (isset($options['digestColumn'])) { + $this->digestColumn = $options['digestColumn']; + } else { + $this->digestColumn = 'digest'; + } + if (isset($options['uuidColumn'])) { + $this->uuidColumn = $options['uuidColumn']; + } else { + $this->uuidColumn = 'username'; + } + if (isset($options['digestPrefix'])) { + $this->digestPrefix = $options['digestPrefix']; + } + } + + /** + * Validates a username and password. + * + * This method should return true or false depending on if login + * succeeded. + * + * @param string $username + * @param string $password + * + * @return bool + */ + public function validateUserPass($username, $password) + { + $stmt = $this->pdo->prepare('SELECT '.$this->digestColumn.' FROM '.$this->tableName.' WHERE '.$this->uuidColumn.' = ?'); + $stmt->execute([$username]); + $result = $stmt->fetchAll(); + + if (!count($result)) { + return false; + } else { + $digest = $result[0][$this->digestColumn]; + + if (isset($this->digestPrefix)) { + $digest = substr($digest, strlen($this->digestPrefix)); + } + + if (password_verify($password, $digest)) { + return true; + } + + return false; + } + } +} diff --git a/sabre/dav/lib/DAV/CorePlugin.php b/sabre/dav/lib/DAV/CorePlugin.php index 74350c28d..dbd8976b1 100644 --- a/sabre/dav/lib/DAV/CorePlugin.php +++ b/sabre/dav/lib/DAV/CorePlugin.php @@ -645,6 +645,10 @@ public function httpCopy(RequestInterface $request, ResponseInterface $response) if (!$this->server->emit('beforeBind', [$copyInfo['destination']])) { return false; } + if (!$this->server->emit('beforeCopy', [$path, $copyInfo['destination']])) { + return false; + } + if ($copyInfo['destinationExists']) { if (!$this->server->emit('beforeUnbind', [$copyInfo['destination']])) { return false; @@ -653,6 +657,7 @@ public function httpCopy(RequestInterface $request, ResponseInterface $response) } $this->server->tree->copy($path, $copyInfo['destination']); + $this->server->emit('afterCopy', [$path, $copyInfo['destination']]); $this->server->emit('afterBind', [$copyInfo['destination']]); // If a resource was overwritten we should send a 204, otherwise a 201 diff --git a/sabre/dav/lib/DAV/StringUtil.php b/sabre/dav/lib/DAV/StringUtil.php index 13a4399e3..edfb7fa5c 100644 --- a/sabre/dav/lib/DAV/StringUtil.php +++ b/sabre/dav/lib/DAV/StringUtil.php @@ -77,10 +77,8 @@ public static function textMatch($haystack, $needle, $collation, $matchType = 'c */ public static function ensureUTF8($input) { - $encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true); - - if ('ISO-8859-1' === $encoding) { - return utf8_encode($input); + if (!mb_check_encoding($input, 'UTF-8') && mb_check_encoding($input, 'ISO-8859-1')) { + return mb_convert_encoding($input, 'UTF-8', 'ISO-8859-1'); } else { return $input; } diff --git a/sabre/dav/lib/DAV/Sync/Plugin.php b/sabre/dav/lib/DAV/Sync/Plugin.php index 32106abb3..8609f759e 100644 --- a/sabre/dav/lib/DAV/Sync/Plugin.php +++ b/sabre/dav/lib/DAV/Sync/Plugin.php @@ -124,6 +124,10 @@ public function syncCollection($uri, SyncCollectionReport $report) throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token'); } + if (!array_key_exists('result_truncated', $changeInfo)) { + $changeInfo['result_truncated'] = false; + } + // Encoding the response $this->sendSyncCollectionResponse( $changeInfo['syncToken'], @@ -131,7 +135,8 @@ public function syncCollection($uri, SyncCollectionReport $report) $changeInfo['added'], $changeInfo['modified'], $changeInfo['deleted'], - $report->properties + $report->properties, + $changeInfo['result_truncated'] ); } @@ -141,7 +146,7 @@ public function syncCollection($uri, SyncCollectionReport $report) * @param string $syncToken * @param string $collectionUrl */ - protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties) + protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties, bool $resultTruncated = false) { $fullPaths = []; @@ -164,6 +169,10 @@ protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $fullPath = $collectionUrl.'/'.$item; $responses[] = new DAV\Xml\Element\Response($fullPath, [], 404); } + if ($resultTruncated) { + $responses[] = new DAV\Xml\Element\Response($collectionUrl.'/', [], 507); + } + $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX.$syncToken); $this->server->httpResponse->setStatus(207); diff --git a/sabre/dav/lib/DAV/Tree.php b/sabre/dav/lib/DAV/Tree.php index 2417979a6..8215e2c39 100644 --- a/sabre/dav/lib/DAV/Tree.php +++ b/sabre/dav/lib/DAV/Tree.php @@ -226,7 +226,7 @@ public function markDirty($path) // flushing the entire cache $path = trim($path, '/'); foreach ($this->cache as $nodePath => $node) { - if ('' === $path || $nodePath == $path || 0 === strpos($nodePath, $path.'/')) { + if ('' === $path || $nodePath == $path || 0 === strpos((string) $nodePath, $path.'/')) { unset($this->cache[$nodePath]); } } diff --git a/sabre/dav/lib/DAV/Version.php b/sabre/dav/lib/DAV/Version.php index b6e646776..c6273ef72 100644 --- a/sabre/dav/lib/DAV/Version.php +++ b/sabre/dav/lib/DAV/Version.php @@ -16,5 +16,5 @@ class Version /** * Full version number. */ - public const VERSION = '4.2.1'; + public const VERSION = '4.4.0'; } diff --git a/sabre/http/CHANGELOG.md b/sabre/http/CHANGELOG.md index 4db8cc772..4650ea540 100644 --- a/sabre/http/CHANGELOG.md +++ b/sabre/http/CHANGELOG.md @@ -1,6 +1,16 @@ ChangeLog ========= +5.1.5 (2022-07-09) +------------------ + +* #184 Remove 4GB file size workaround for 32bit OS / Stream Videos on IOS (@schoetju) + +5.1.4 (2022-06-24) +------------------ + +* #182 Fix encoding detection on PHP 8.1 (@come-nc) + 5.1.3 (2021-11-04) ------------------ diff --git a/sabre/http/lib/Sapi.php b/sabre/http/lib/Sapi.php index 823d5df25..d0eb2a6ab 100644 --- a/sabre/http/lib/Sapi.php +++ b/sabre/http/lib/Sapi.php @@ -89,41 +89,33 @@ public static function sendResponse(ResponseInterface $response) if (null !== $contentLength) { $output = fopen('php://output', 'wb'); if (is_resource($body) && 'stream' == get_resource_type($body)) { - if (PHP_INT_SIZE > 4) { - // use the dedicated function on 64 Bit systems - // a workaround to make PHP more possible to use mmap based copy, see https://github.com/sabre-io/http/pull/119 - $left = (int) $contentLength; - // copy with 4MiB chunks - $chunk_size = 4 * 1024 * 1024; - stream_set_chunk_size($output, $chunk_size); - // If this is a partial response, flush the beginning bytes until the first position that is a multiple of the page size. - $contentRange = $response->getHeader('Content-Range'); - // Matching "Content-Range: bytes 1234-5678/7890" - if (null !== $contentRange && preg_match('/^bytes\s([0-9]+)-([0-9]+)\//i', $contentRange, $matches)) { - // 4kB should be the default page size on most architectures - $pageSize = 4096; - $offset = (int) $matches[1]; - $delta = ($offset % $pageSize) > 0 ? ($pageSize - $offset % $pageSize) : 0; - if ($delta > 0) { - $left -= stream_copy_to_stream($body, $output, min($delta, $left)); - } + // a workaround to make PHP more possible to use mmap based copy, see https://github.com/sabre-io/http/pull/119 + $left = (int) $contentLength; + // copy with 4MiB chunks + $chunk_size = 4 * 1024 * 1024; + stream_set_chunk_size($output, $chunk_size); + // If this is a partial response, flush the beginning bytes until the first position that is a multiple of the page size. + $contentRange = $response->getHeader('Content-Range'); + // Matching "Content-Range: bytes 1234-5678/7890" + if (null !== $contentRange && preg_match('/^bytes\s([0-9]+)-([0-9]+)\//i', $contentRange, $matches)) { + // 4kB should be the default page size on most architectures + $pageSize = 4096; + $offset = (int) $matches[1]; + $delta = ($offset % $pageSize) > 0 ? ($pageSize - $offset % $pageSize) : 0; + if ($delta > 0) { + $left -= stream_copy_to_stream($body, $output, min($delta, $left)); } - while ($left > 0) { - $copied = stream_copy_to_stream($body, $output, min($left, $chunk_size)); - // stream_copy_to_stream($src, $dest, $maxLength) must return the number of bytes copied or false in case of failure - // But when the $maxLength is greater than the total number of bytes remaining in the stream, - // It returns the negative number of bytes copied - // So break the loop in such cases. - if ($copied <= 0) { - break; - } - $left -= $copied; - } - } else { - // workaround for 32 Bit systems to avoid stream_copy_to_stream - while (!feof($body)) { - fwrite($output, fread($body, 8192)); + } + while ($left > 0) { + $copied = stream_copy_to_stream($body, $output, min($left, $chunk_size)); + // stream_copy_to_stream($src, $dest, $maxLength) must return the number of bytes copied or false in case of failure + // But when the $maxLength is greater than the total number of bytes remaining in the stream, + // It returns the negative number of bytes copied + // So break the loop in such cases. + if ($copied <= 0) { + break; } + $left -= $copied; } } else { fwrite($output, $body, (int) $contentLength); diff --git a/sabre/http/lib/Version.php b/sabre/http/lib/Version.php index f182979c6..f0c83177d 100644 --- a/sabre/http/lib/Version.php +++ b/sabre/http/lib/Version.php @@ -16,5 +16,5 @@ class Version /** * Full version number. */ - const VERSION = '5.1.3'; + const VERSION = '5.1.5'; } diff --git a/sabre/http/lib/functions.php b/sabre/http/lib/functions.php index 97673da46..51048346c 100644 --- a/sabre/http/lib/functions.php +++ b/sabre/http/lib/functions.php @@ -404,11 +404,9 @@ function decodePath(string $path): string function decodePathSegment(string $path): string { $path = rawurldecode($path); - $encoding = mb_detect_encoding($path, ['UTF-8', 'ISO-8859-1']); - switch ($encoding) { - case 'ISO-8859-1': - $path = utf8_encode($path); + if (!mb_check_encoding($path, 'UTF-8') && mb_check_encoding($path, 'ISO-8859-1')) { + $path = mb_convert_encoding($path, 'UTF-8', 'ISO-8859-1'); } return $path; diff --git a/sabre/vobject/lib/Component.php b/sabre/vobject/lib/Component.php index f33b628a7..cb08c0061 100644 --- a/sabre/vobject/lib/Component.php +++ b/sabre/vobject/lib/Component.php @@ -249,7 +249,7 @@ function ($child) use ($group) { $result = []; foreach ($this->children as $childGroup) { foreach ($childGroup as $child) { - if ($child instanceof Property && strtoupper($child->group) === $group) { + if ($child instanceof Property && $child->group && strtoupper($child->group) === $group) { $result[] = $child; } } diff --git a/sabre/vobject/lib/Component/VCard.php b/sabre/vobject/lib/Component/VCard.php index eac789842..90a6df72f 100644 --- a/sabre/vobject/lib/Component/VCard.php +++ b/sabre/vobject/lib/Component/VCard.php @@ -291,6 +291,11 @@ public function validate($options = 0) $this->FN = (string) $this->ORG; $repaired = true; + // Otherwise, the NICKNAME property may work + } elseif (isset($this->NICKNAME)) { + $this->FN = (string) $this->NICKNAME; + $repaired = true; + // Otherwise, the EMAIL property may work } elseif (isset($this->EMAIL)) { $this->FN = (string) $this->EMAIL; diff --git a/sabre/vobject/lib/Property/ICalendar/CalAddress.php b/sabre/vobject/lib/Property/ICalendar/CalAddress.php index 2dbbc6eaf..c90967d79 100644 --- a/sabre/vobject/lib/Property/ICalendar/CalAddress.php +++ b/sabre/vobject/lib/Property/ICalendar/CalAddress.php @@ -53,7 +53,11 @@ public function getNormalizedValue() return $input; } list($schema, $everythingElse) = explode(':', $input, 2); + $schema = strtolower($schema); + if ('mailto' === $schema) { + $everythingElse = strtolower($everythingElse); + } - return strtolower($schema).':'.$everythingElse; + return $schema.':'.$everythingElse; } } diff --git a/sabre/vobject/lib/StringUtil.php b/sabre/vobject/lib/StringUtil.php index 2333d6ab9..b04539e4a 100644 --- a/sabre/vobject/lib/StringUtil.php +++ b/sabre/vobject/lib/StringUtil.php @@ -40,23 +40,11 @@ public static function isUTF8($str) */ public static function convertToUTF8($str) { - $encoding = mb_detect_encoding($str, ['UTF-8', 'ISO-8859-1', 'WINDOWS-1252'], true); - - switch ($encoding) { - case 'ISO-8859-1': - $newStr = utf8_encode($str); - break; - /* Unreachable code. Not sure yet how we can improve this - * situation. - case 'WINDOWS-1252' : - $newStr = iconv('cp1252', 'UTF-8', $str); - break; - */ - default: - $newStr = $str; + if (!mb_check_encoding($str, 'UTF-8') && mb_check_encoding($str, 'ISO-8859-1')) { + $str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1'); } // Removing any control characters - return preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $newStr); + return preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $str); } } diff --git a/sabre/vobject/lib/Version.php b/sabre/vobject/lib/Version.php index 64938bf0b..ff8cf49c2 100644 --- a/sabre/vobject/lib/Version.php +++ b/sabre/vobject/lib/Version.php @@ -14,5 +14,5 @@ class Version /** * Full version number. */ - const VERSION = '4.4.1'; + const VERSION = '4.4.2'; }