From a7ba436f2f31a689611b287efc9104d733113850 Mon Sep 17 00:00:00 2001 From: Florian Schlichting Date: Sun, 7 Jan 2018 00:37:29 +0100 Subject: [PATCH] advertise support for principal-match REPORT and a few more bits inspired by CalDAV/aclreports.xml: - strict Depth header checking - principal-match: match on dav_name if not $match_self - principal-match can "alternatively" return resources in a collection that belong to a principal, like a user's calendars when we query the principal URI --- inc/DAVResource.php | 1 + inc/caldav-REPORT-pps-set.php | 4 ++ inc/caldav-REPORT-principal-match.php | 26 +++++++--- inc/caldav-REPORT-principal.php | 6 ++- .../0531-iCal4-PROPFIND.result | 9 +++- .../0548-iCal-PROPFIND.result | 49 ++++++++++++++++++- .../0916-PROPFIND-supported-stuff.result | 9 +++- .../0917-PROPFIND-supported-stuff.result | 9 +++- .../0918-PROPFIND-supported-stuff.result | 9 +++- .../0919-PROPFIND-supported-stuff.result | 9 +++- .../0920-PROPFIND-supported-stuff.result | 9 +++- 11 files changed, 117 insertions(+), 23 deletions(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index 3ff175de..2361d5b1 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -925,6 +925,7 @@ EOQRY; 'DAV::principal-property-search' => '', 'DAV::principal-search-property-set' => '', 'DAV::expand-property' => '', + 'DAV::principal-match' => '', 'DAV::sync-collection' => '' ); diff --git a/inc/caldav-REPORT-pps-set.php b/inc/caldav-REPORT-pps-set.php index 90caad28..954ddbe4 100644 --- a/inc/caldav-REPORT-pps-set.php +++ b/inc/caldav-REPORT-pps-set.php @@ -25,6 +25,10 @@ $principal_search_property_set = array( 'urn:ietf:params:xml:ns:caldav:calendar-user-address-set' ); +if ( $request->depth > 0 ) { + $request->DoResponse( 400, 'The principal-search-property-set REPORT is only defined for Depth "0".' ); +} + $responses = array(); foreach( $principal_search_property_set AS $k => $tag ) { $responses[] = property_response( $reply, $tag ); diff --git a/inc/caldav-REPORT-principal-match.php b/inc/caldav-REPORT-principal-match.php index 40310899..fea91c26 100644 --- a/inc/caldav-REPORT-principal-match.php +++ b/inc/caldav-REPORT-principal-match.php @@ -1,12 +1,13 @@ NeedPrivilege(array('DAV::read','DAV::read-current-user-privilege-set','DAV::read-acl')); +if ( $request->depth > 0 ) { + $request->DoResponse( 400, 'The principal-match REPORT is only defined for Depth "0".' ); +} + /** - * Build the array of properties to include in the report output + * Determine which principal we're looking for */ $match = $xmltree->GetPath('/DAV::principal-match/DAV::self'); if ( count ( $match ) == 0 ) { @@ -31,20 +32,31 @@ if ( $match_self ) { $params = array(':username' => $session->username ); } else { + $where = 'dav_name = :dav_name'; $params = array(':dav_name'=>'/'.$request->principal->GetProperty('username').'/'); } +$sql = "SELECT * FROM dav_principal WHERE $where ORDER BY principal_id LIMIT 100"; + +if ( $target->IsPrincipal() ) { + // The request path is more specific, so ALTERNATIVELY, + // we find this principal's resources (collections) instead + $sql = "SELECT * FROM collection WHERE user_no = :user_no"; + $params = array(':user_no' => $target->user_no() ); +} -if ( $where != "" ) $where = "WHERE $where"; -$sql = "SELECT * FROM dav_principal $where ORDER BY principal_id LIMIT 100"; $qry = new AwlQuery($sql, $params); +/** + * Build the array of properties to include in the report output + */ $get_props = $xmltree->GetPath('/DAV::principal-match/DAV::prop/*'); $properties = array(); foreach( $get_props AS $k1 => $v1 ) { $properties[] = $v1->GetNSTag(); } +$responses = array(); if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ) { while( $row = $qry->Fetch() ) { $principal = new DAVResource($row); @@ -54,4 +66,4 @@ if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ) { $multistatus = new XMLElement( "multistatus", $responses, $reply->GetXmlNsArray() ); -$request->XMLResponse( 207, $multistatus ); \ No newline at end of file +$request->XMLResponse( 207, $multistatus ); diff --git a/inc/caldav-REPORT-principal.php b/inc/caldav-REPORT-principal.php index f979bdfe..e9da1041 100644 --- a/inc/caldav-REPORT-principal.php +++ b/inc/caldav-REPORT-principal.php @@ -1,7 +1,8 @@ depth > 0 ) { + $request->DoResponse( 400, 'The principal-property-search REPORT is only defined for Depth "0".' ); +} /** * Build the array of properties to include in the report output @@ -71,6 +72,7 @@ foreach( $get_props AS $k1 => $v1 ) { $properties[] = $v1->GetNSTag(); } +$responses = array(); if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ) { while( $row = $qry->Fetch() ) { $principal = new DAVResource($row); diff --git a/testing/tests/regression-suite/0531-iCal4-PROPFIND.result b/testing/tests/regression-suite/0531-iCal4-PROPFIND.result index d5a0c262..325433c6 100644 --- a/testing/tests/regression-suite/0531-iCal4-PROPFIND.result +++ b/testing/tests/regression-suite/0531-iCal4-PROPFIND.result @@ -2,8 +2,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy -ETag: "ae6b3ed31d2295a38ad54bdf12fe02a7" -Content-Length: 1655 +ETag: "1c7781ef8567ba3018e5924858102296" +Content-Length: 1761 Content-Type: text/xml; charset="utf-8" @@ -51,6 +51,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + diff --git a/testing/tests/regression-suite/0548-iCal-PROPFIND.result b/testing/tests/regression-suite/0548-iCal-PROPFIND.result index 5f5d44e6..9f3df692 100644 --- a/testing/tests/regression-suite/0548-iCal-PROPFIND.result +++ b/testing/tests/regression-suite/0548-iCal-PROPFIND.result @@ -4,8 +4,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy -ETag: "e76e5a37264c0b44f88f8456c27a7aaa" -Content-Length: 27747 +ETag: "e6d929727ad5e85f7db37f1e7c091f6a" +Content-Length: 28701 Content-Type: text/xml; charset="utf-8" @@ -80,6 +80,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -204,6 +209,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -330,6 +340,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -460,6 +475,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -604,6 +624,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -733,6 +758,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -854,6 +884,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -981,6 +1016,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + @@ -1121,6 +1161,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + diff --git a/testing/tests/regression-suite/0916-PROPFIND-supported-stuff.result b/testing/tests/regression-suite/0916-PROPFIND-supported-stuff.result index c2380b3b..94399b70 100644 --- a/testing/tests/regression-suite/0916-PROPFIND-supported-stuff.result +++ b/testing/tests/regression-suite/0916-PROPFIND-supported-stuff.result @@ -2,8 +2,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy -ETag: "8d5e76c5b7b5676fc36e38cfad77c5db" -Content-Length: 1277 +ETag: "be4b763e94c9a88fb82f45f25d0a6e89" +Content-Length: 1383 Content-Type: text/xml; charset="utf-8" @@ -37,6 +37,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + diff --git a/testing/tests/regression-suite/0917-PROPFIND-supported-stuff.result b/testing/tests/regression-suite/0917-PROPFIND-supported-stuff.result index 045034ee..46152c1c 100644 --- a/testing/tests/regression-suite/0917-PROPFIND-supported-stuff.result +++ b/testing/tests/regression-suite/0917-PROPFIND-supported-stuff.result @@ -2,8 +2,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy -ETag: "3447a04184df5d673f50e8c7a0952a68" -Content-Length: 1611 +ETag: "f36602c450120819191b73e42c5fccaa" +Content-Length: 1717 Content-Type: text/xml; charset="utf-8" @@ -49,6 +49,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + diff --git a/testing/tests/regression-suite/0918-PROPFIND-supported-stuff.result b/testing/tests/regression-suite/0918-PROPFIND-supported-stuff.result index eaea5200..a3e77b1b 100644 --- a/testing/tests/regression-suite/0918-PROPFIND-supported-stuff.result +++ b/testing/tests/regression-suite/0918-PROPFIND-supported-stuff.result @@ -2,8 +2,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy -ETag: "25501a258bef17f959a7045cac35322a" -Content-Length: 2027 +ETag: "a55aa07ee821b9f4dd4eea96e192aa89" +Content-Length: 2133 Content-Type: text/xml; charset="utf-8" @@ -48,6 +48,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + diff --git a/testing/tests/regression-suite/0919-PROPFIND-supported-stuff.result b/testing/tests/regression-suite/0919-PROPFIND-supported-stuff.result index bad85872..7d53fdd9 100644 --- a/testing/tests/regression-suite/0919-PROPFIND-supported-stuff.result +++ b/testing/tests/regression-suite/0919-PROPFIND-supported-stuff.result @@ -2,8 +2,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy -ETag: "98ceb8bb48fbdd547226d0b28aadd942" -Content-Length: 1699 +ETag: "be682462fd8bacf3d7189fbac09a7af5" +Content-Length: 1805 Content-Type: text/xml; charset="utf-8" @@ -48,6 +48,11 @@ Content-Type: text/xml; charset="utf-8" + + + + + diff --git a/testing/tests/regression-suite/0920-PROPFIND-supported-stuff.result b/testing/tests/regression-suite/0920-PROPFIND-supported-stuff.result index e2c6ae9c..43133d20 100644 --- a/testing/tests/regression-suite/0920-PROPFIND-supported-stuff.result +++ b/testing/tests/regression-suite/0920-PROPFIND-supported-stuff.result @@ -2,8 +2,8 @@ HTTP/1.1 207 Multi-Status Date: Dow, 01 Jan 2000 00:00:00 GMT DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy -ETag: "f4ace4415ef70e47f318ae774aaaac48" -Content-Length: 1636 +ETag: "6cd1545a5b4de69844a890f732119fa0" +Content-Length: 1742 Content-Type: text/xml; charset="utf-8" @@ -46,6 +46,11 @@ Content-Type: text/xml; charset="utf-8" + + + + +