Add first cut implementation of principal-match report.

This commit is contained in:
Andrew McMillan 2011-05-18 23:39:46 +12:00
parent 17104fc027
commit 4bba200385
6 changed files with 217 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<?php
$responses = array();
$request->NeedPrivilege(array('DAV::read','DAV::read-current-user-privilege-set','DAV::read-acl'));
/**
* Build the array of properties to include in the report output
*/
$match = $xmltree->GetPath('/DAV::principal-match/DAV::self');
if ( count ( $match ) == 0 ) {
$match = $xmltree->GetPath('/DAV::principal-match/DAV::principal-property');
$match_self = false;
}
else {
$match_self = true;
}
if ( count ( $match ) == 0 ) {
$request->DoResponse( 400, 'Badly formed principal-match REPORT request.' );
}
$target = new DAVResource($request->path);
$where = '';
if ( $match_self ) {
// Technically we should restrict to finding the principal somewhere *below* the
// request path in the hierarchy, but we'll quietly ignore that because it's
// unlikely that anything would actually be wanting that behaviour.
$where .= 'username = :username';
$params = array(':username' => $session->username );
}
else {
$params = array(':dav_name'=>'/'.$request->principal->GetProperty('username').'/');
}
if ( $where != "" ) $where = "WHERE $where";
$sql = "SELECT * FROM dav_principal $where ORDER BY principal_id LIMIT 100";
$qry = new AwlQuery($sql, $params);
$get_props = $xmltree->GetPath('/DAV::principal-match/DAV::prop/*');
$properties = array();
foreach( $get_props AS $k1 => $v1 ) {
$properties[] = $v1->GetTag();
}
if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows() > 0 ) {
while( $row = $qry->Fetch() ) {
$principal = new DAVResource($row);
$responses[] = $principal->RenderAsXML( $properties, $reply );
}
}
$multistatus = new XMLElement( "multistatus", $responses, $reply->GetXmlNsArray() );
$request->XMLResponse( 207, $multistatus );

View File

@ -66,6 +66,9 @@ switch( $xmltree->GetTag() ) {
case 'DAV::expand-property':
include("caldav-REPORT-expand-property.php");
exit; // Not that it should return anyway.
case 'DAV::principal-match':
include("caldav-REPORT-principal-match.php");
exit; // Not that it should return anyway.
}

View File

@ -0,0 +1,22 @@
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, calendar-proxy, bind, addressbook
ETag: "7656abee424b0f6763c3851c78613769"
Content-Length: 362
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
<response>
<href>/caldav.php/user1/</href>
<propstat>
<prop>
<C:addressbook-home-set>
<href>/caldav.php/user1/</href>
</C:addressbook-home-set>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,23 @@
#
# principal-match REPORT on self as user1
#
TYPE=REPORT
URL=http://mycaldav/caldav.php/
AUTH=user1:user1
HEADER=User-Agent: DAViCal Testing
HEADER=Accept: text/xml
HEADER=Content-Type: text/xml; charset=utf-8
HEADER=Depth: 0
HEAD
BEGINDATA
<?xml version="1.0" encoding="utf-8" ?>
<D:principal-match xmlns:D="DAV:">
<D:self/>
<D:prop>
<C:addressbook-home-set xmlns:C="urn:ietf:params:xml:ns:carddav"/>
</D:prop>
</D:principal-match>
ENDDATA

View File

@ -0,0 +1,83 @@
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, calendar-proxy, bind, addressbook
ETag: "c6026dd8dbea9512cd6e210a06f30c4a"
Content-Length: 1795
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
<response>
<href>/caldav.php/user1/</href>
<propstat>
<prop>
<C:addressbook-home-set>
<href>/caldav.php/user1/</href>
</C:addressbook-home-set>
<displayname>User 1</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/user2/</href>
<propstat>
<prop>
<C:addressbook-home-set>
<href>/caldav.php/user2/</href>
</C:addressbook-home-set>
<displayname>User 2</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/user3/</href>
<propstat>
<prop>
<C:addressbook-home-set>
<href>/caldav.php/user3/</href>
</C:addressbook-home-set>
<displayname>User 3</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/user4/</href>
<propstat>
<prop>
<C:addressbook-home-set>
<href>/caldav.php/user4/</href>
</C:addressbook-home-set>
<displayname>User 4</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/user5/</href>
<propstat>
<prop>
<C:addressbook-home-set>
<href>/caldav.php/user5/</href>
</C:addressbook-home-set>
<displayname>User 5</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/User%20Six/</href>
<propstat>
<prop>
<C:addressbook-home-set>
<href>/caldav.php/User%20Six/</href>
</C:addressbook-home-set>
<displayname>User 6</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,29 @@
#
# principal-match REPORT on a principal-property (displayname)
#
TYPE=REPORT
URL=http://mycaldav/caldav.php/
AUTH=user1:user1
HEADER=User-Agent: DAViCal Testing
HEADER=Accept: text/xml
HEADER=Content-Type: text/xml; charset=utf-8
HEADER=Depth: 0
HEAD
BEGINDATA
<?xml version="1.0" encoding="utf-8" ?>
<D:principal-property-search xmlns:D="DAV:">
<D:property-search>
<D:prop>
<D:displayname/>
</D:prop>
<D:match>User</D:match>
</D:property-search>
<D:prop>
<C:addressbook-home-set xmlns:C="urn:ietf:params:xml:ns:carddav"/>
<D:displayname/>
</D:prop>
</D:principal-property-search>
ENDDATA