From 5edf66321d2cf4d94081791a019f4ae828ae1eba Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 23 Jun 2016 00:48:07 +0100 Subject: [PATCH] Fix common etag match code, use it everywhere. --- inc/CalDAVRequest.php | 3 ++- inc/caldav-DELETE.php | 4 +--- inc/caldav-MOVE.php | 26 +------------------------- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/inc/CalDAVRequest.php b/inc/CalDAVRequest.php index c3e7ed89..f395671c 100644 --- a/inc/CalDAVRequest.php +++ b/inc/CalDAVRequest.php @@ -1059,7 +1059,8 @@ EOSQL; else $trim_chars = ' '; - if ( isset($this->etag_if_match) && $this->etag_if_match != '' && trim( $this->etag_if_match, $trim_chars) != trim( $dest_etag, $trim_chars ) ) { + if ( isset($this->etag_if_match) && $this->etag_if_match != '' && $this->etag_if_match != '*' + && trim( $this->etag_if_match, $trim_chars) != trim( $dest_etag, $trim_chars ) ) { /** * RFC2068, 14.25: * If none of the entity tags match, or if "*" is given and no current diff --git a/inc/caldav-DELETE.php b/inc/caldav-DELETE.php index 98693f41..ba7d4573 100644 --- a/inc/caldav-DELETE.php +++ b/inc/caldav-DELETE.php @@ -79,9 +79,7 @@ if ( $dav_resource->IsCollection() ) { $cache->releaseLock($myLock); } else { - if ( isset($request->etag_if_match) && $request->etag_if_match != $dav_resource->unique_tag() && $request->etag_if_match != "*" ) { - $request->DoResponse( 412, translate("Resource has changed on server - not deleted") ); - } + $request->CheckEtagMatch( $dav_resource->Exists(), $dav_resource->unique_tag() ); // Check to see if we need to do any scheduling transactions for this one. do_scheduling_for_delete($dav_resource); diff --git a/inc/caldav-MOVE.php b/inc/caldav-MOVE.php index 178ffb75..94abff72 100644 --- a/inc/caldav-MOVE.php +++ b/inc/caldav-MOVE.php @@ -57,31 +57,7 @@ if ( $src->IsCollection() ) { }; } else { - if ( (isset($request->etag_if_match) && $request->etag_if_match != '' ) - || ( isset($request->etag_none_match) && $request->etag_none_match != '') ) { - - /** - * RFC2068, 14.25: - * If none of the entity tags match, or if "*" is given and no current - * entity exists, the server MUST NOT perform the requested method, and - * MUST return a 412 (Precondition Failed) response. - * - * RFC2068, 14.26: - * If any of the entity tags match the entity tag of the entity that - * would have been returned in the response to a similar GET request - * (without the If-None-Match header) on that resource, or if "*" is - * given and any current entity exists for that resource, then the - * server MUST NOT perform the requested method. - */ - $error = ''; - if ( isset($request->etag_if_match) && $request->etag_if_match != $src->unique_tag() ) { - $error = translate( 'Existing resource does not match "If-Match" header - not accepted.'); - } - else if ( isset($request->etag_none_match) && $request->etag_none_match != '' && $request->etag_none_match == $src->unique_tag() ) { - $error = translate( 'Existing resource matches "If-None-Match" header - not accepted.'); - } - if ( $error != '' ) $request->DoResponse( 412, $error ); - } + $request->CheckEtagMatch( $src->Exists(), $src->unique_tag() ); } $src->NeedPrivilege('DAV::unbind');