Correct supported-privilege-set response for enclosed privileges.

This commit is contained in:
Andrew McMillan 2009-10-08 08:15:57 +13:00
parent 19fdb8baf2
commit bede1cba07
2 changed files with 114 additions and 51 deletions

View File

@ -77,12 +77,33 @@ class CalDAVRequest
*/
var $collection_type;
/**
* A static structure of supported privileges.
*/
var $supported_privileges;
/**
* Create a new CalDAVRequest object.
*/
function CalDAVRequest( $options = array() ) {
global $session, $c, $debugging;
$this->supported_privileges = array(
'all' => array(
'read' => 'Read the content of a resource or collection',
'write' => array(
'bind' => 'Create a resource or collection',
'unbind' => 'Delete a resource or collection',
'write-content' => 'Write content',
'write-properties' => 'Write properties'
),
'urn:ietf:params:xml:ns:caldav:read-free-busy' => 'Read the free/busy information for a calendar collection',
'read-acl' => 'Read ACLs for a resource or collection',
'write-acl' => 'Write ACLs for a resource or collection',
'unlock' => 'Remove a lock'
)
);
$this->options = $options;
if ( !isset($this->options['allow_by_email']) ) $this->options['allow_by_email'] = false;
$this->principal = (object) array( 'username' => $session->username, 'user_no' => $session->user_no );
@ -727,27 +748,46 @@ EOSQL;
}
/**
* Returns the array of supported privileges converted into XMLElements
*/
function RenderSupportedPrivileges( $privs = null ) {
global $reply;
$privileges = array();
if ( $privs === null ) $privs = $this->supported_privileges;
foreach( $privs AS $k => $v ) {
dbg_error_log( 'caldav', 'Adding privilege "%s" which is "%s".', $k, $v );
$privilege = new XMLElement('privilege');
$reply->NSElement($privilege,$k);
$privset = array($privilege);
if ( is_array($v) ) {
dbg_error_log( 'caldav', '"%s" is a container of sub-privileges.', $k );
$privset = array_merge($privset, $this->RenderSupportedPrivileges($v));
}
else if ( $v == 'abstract' ) {
dbg_error_log( 'caldav', '"%s" is an abstract privilege.', $v );
$privset[] = new XMLElement('abstract');
}
else if ( strlen($v) > 1 ) {
$privset[] = new XMLElement('description', $v);
}
$privileges[] = new XMLElement('supported-privilege',$privset);
}
return $privileges;
}
/**
* Returns the array of privilege names converted into XMLElements
*/
function RenderPrivileges($privilege_names, $container=null) {
function RenderPrivileges($privilege_names) {
global $reply;
$privileges = array();
foreach( $privilege_names AS $k => $v ) {
dbg_error_log( 'caldav', 'Adding privilege "%s" which is "%s".', $k, $v );
$privilege = new XMLElement('privilege');
$reply->NSElement($privilege,$k);
if ( isset($container) ) {
$privset = array($privilege);
if ( $v == 'abstract' ) {
dbg_error_log( 'caldav', '"%s" is an abstract privilege.', $v );
$privset[] = new XMLElement('abstract');
}
$privileges[] = new XMLElement($container,$privset);
}
else {
$privileges[] = $privilege;
}
$privileges[] = $privilege;
}
return $privileges;
}
@ -801,7 +841,7 @@ EOSQL;
case 'DAV::supported-privilege-set':
dbg_error_log( 'caldav', 'Processing "%s" on "%s".', $tag, $this->path );
$prop->NewElement('supported-privilege-set', $this->RenderPrivileges( $this->SupportedPrivileges(), 'supported-privilege') );
$prop->NewElement('supported-privilege-set', $this->RenderSupportedPrivileges() );
break;
default:

View File

@ -1,8 +1,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
ETag: "e3119e4ec64afd062ae2634ebd232f0f"
Content-Length: 1235
ETag: "e01e87a334e05b0efb2deedc5fa7ae50"
Content-Length: 2219
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
@ -16,42 +16,65 @@ Content-Type: text/xml; charset="utf-8"
<privilege>
<all/>
</privilege>
<abstract/>
</supported-privilege>
<supported-privilege>
<privilege>
<read/>
</privilege>
</supported-privilege>
<supported-privilege>
<privilege>
<write/>
</privilege>
</supported-privilege>
<supported-privilege>
<privilege>
<bind/>
</privilege>
</supported-privilege>
<supported-privilege>
<privilege>
<unbind/>
</privilege>
</supported-privilege>
<supported-privilege>
<privilege>
<write-content/>
</privilege>
</supported-privilege>
<supported-privilege>
<privilege>
<write-properties/>
</privilege>
</supported-privilege>
<supported-privilege>
<privilege>
<C:read-free-busy/>
</privilege>
<supported-privilege>
<privilege>
<read/>
</privilege>
<description>Read the content of a resource or collection</description>
</supported-privilege>
<supported-privilege>
<privilege>
<write/>
</privilege>
<supported-privilege>
<privilege>
<bind/>
</privilege>
<description>Create a resource or collection</description>
</supported-privilege>
<supported-privilege>
<privilege>
<unbind/>
</privilege>
<description>Delete a resource or collection</description>
</supported-privilege>
<supported-privilege>
<privilege>
<write-content/>
</privilege>
<description>Write content</description>
</supported-privilege>
<supported-privilege>
<privilege>
<write-properties/>
</privilege>
<description>Write properties</description>
</supported-privilege>
</supported-privilege>
<supported-privilege>
<privilege>
<C:read-free-busy/>
</privilege>
<description>Read the free/busy information for a calendar collection</description>
</supported-privilege>
<supported-privilege>
<privilege>
<read-acl/>
</privilege>
<description>Read ACLs for a resource or collection</description>
</supported-privilege>
<supported-privilege>
<privilege>
<write-acl/>
</privilege>
<description>Write ACLs for a resource or collection</description>
</supported-privilege>
<supported-privilege>
<privilege>
<unlock/>
</privilege>
<description>Remove a lock</description>
</supported-privilege>
</supported-privilege>
</supported-privilege-set>
</prop>