mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-08-24 17:36:39 +00:00
Add first cut implementation of principal-match report.
This commit is contained in:
parent
17104fc027
commit
4bba200385
57
inc/caldav-REPORT-principal-match.php
Normal file
57
inc/caldav-REPORT-principal-match.php
Normal 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 );
|
||||
@ -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.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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>
|
||||
@ -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
|
||||
|
||||
@ -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>
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user