12 require_once(
'AwlCache.php');
13 require_once(
'AwlQuery.php');
14 require_once(
'DAVPrincipal.php');
15 require_once(
'DAVTicket.php');
16 require_once(
'iCalendar.php');
39 protected $unique_tag;
54 protected $resourcetypes;
59 protected $contenttype;
64 protected $bound_from;
84 private $_is_collection;
89 private $_is_principal;
94 private $_is_calendar;
104 private $_is_external;
109 private $_is_addressbook;
114 private $_is_proxy_resource;
124 private $supported_methods;
129 private $supported_reports;
134 private $dead_properties;
139 private $supported_components;
146 private $collection_type;
148 private $displayname;
151 private $principal_id;
152 private $resource_id;
154 private $access_tickets;
155 private $parent_container_type;
165 private $_collection_is_cacheable;
177 $this->exists = null;
182 $this->collection = null;
183 $this->principal = null;
184 $this->parent = null;
185 $this->resourcetypes = null;
186 $this->contenttype = null;
187 $this->privileges = null;
188 $this->dead_properties = null;
189 $this->supported_methods = null;
190 $this->supported_reports = null;
192 $this->_is_collection =
false;
193 $this->_is_principal =
false;
194 $this->_is_calendar =
false;
195 $this->_is_binding =
false;
196 $this->_is_external =
false;
197 $this->_is_addressbook =
false;
198 $this->_is_proxy_resource =
false;
199 $this->_collection_is_cacheable =
false;
201 if ( isset($prefetched_collection) ) {
202 $this->collection = $prefetched_collection;
205 if ( isset($parameters) && is_object($parameters) ) {
208 else if ( isset($parameters) && is_array($parameters) ) {
209 if ( isset($parameters[
'path']) ) {
210 $this->
FromPath($parameters[
'path']);
213 else if ( isset($parameters) && is_string($parameters) ) {
226 if ( $row == null )
return;
228 $this->exists =
true;
230 $this->
bound_from = (isset($row->bound_from)? $row->bound_from : $row->dav_name);
231 $this->_is_collection = preg_match(
'{/$}', $this->
dav_name );
233 if ( $this->_is_collection ) {
234 $this->contenttype =
'httpd/unix-directory';
235 $this->collection = (object) array();
238 $this->_is_principal = preg_match(
'{^/[^/]+/$}', $this->
dav_name );
239 if ( preg_match(
'#^(/principals/[^/]+/[^/]+)/?$#', $this->
dav_name, $matches) ) {
240 $this->collection->dav_name = $matches[1].
'/';
241 $this->collection->type =
'principal_link';
242 $this->_is_principal =
true;
247 if ( isset($row->dav_id) ) $this->
resource_id = $row->dav_id;
250 dbg_error_log(
'DAVResource',
':FromRow: Named "%s" is%s a collection.', $this->
dav_name, ($this->_is_collection?
'':
' not') );
252 foreach( $row AS $k => $v ) {
253 if ( $this->_is_collection )
254 $this->collection->{$k} = $v;
263 case 'resourcetypes':
264 if ( $this->_is_collection ) $this->{$k} = $v;
274 if ( $this->_is_collection ) {
275 if ( !isset( $this->collection->type ) || $this->collection->type ==
'collection' ) {
276 if ( $this->_is_principal )
277 $this->collection->type =
'principal';
278 else if ( $row->is_calendar ==
't' ) {
279 $this->collection->type =
'calendar';
281 else if ( $row->is_addressbook ==
't' ) {
282 $this->collection->type =
'addressbook';
284 else if ( isset($row->is_proxy) && $row->is_proxy ==
't' ) {
285 $this->collection->type =
'proxy';
287 else if ( preg_match(
'#^((/[^/]+/)\.(in|out)/)[^/]*$#', $this->
dav_name, $matches ) )
288 $this->collection->type =
'schedule-'. $matches[3].
'box';
290 $this->collection->type =
'root';
292 $this->collection->type =
'collection';
295 $this->_is_calendar = ($this->collection->is_calendar ==
't');
296 $this->_is_addressbook = ($this->collection->is_addressbook ==
't');
297 $this->_is_proxy_resource = ($this->collection->type ==
'proxy');
298 if ( $this->_is_principal && !isset($this->resourcetypes) ) {
299 $this->resourcetypes =
'<DAV::collection/><DAV::principal/>';
301 else if ( $this->_is_proxy_resource ) {
302 $this->resourcetypes = $this->collection->resourcetypes;
303 preg_match(
'#^/[^/]+/calendar-proxy-(read|write)/?[^/]*$#', $this->
dav_name, $matches );
304 $this->proxy_type = $matches[1];
306 if ( isset($this->collection->dav_displayname) ) $this->collection->displayname = $this->collection->dav_displayname;
309 $this->resourcetypes =
'';
310 if ( isset($this->
resource->caldav_data) ) {
312 if ( strtoupper(substr($this->
resource->caldav_data,0,15)) ==
'BEGIN:VCALENDAR' ) {
313 $this->contenttype =
'text/calendar';
314 if ( isset($this->
resource->caldav_type) ) $this->contenttype .=
"; component=" . strtolower($this->
resource->caldav_type);
316 $vcal =
new iCalComponent($this->
resource->caldav_data);
317 $confidential = $vcal->CloneConfidential();
318 $this->
resource->caldav_data = $confidential->Render();
319 $this->
resource->displayname = $this->
resource->summary = translate(
'Busy');
320 $this->
resource->description = null;
325 if ( isset($this->
resource->class) && strtoupper($this->
resource->class)==
'CONFIDENTIAL' && !$this->HavePrivilegeTo(
'all') && $session->user_no != $this->
resource->user_no ) {
326 $vcal =
new iCalComponent($this->
resource->caldav_data);
327 $confidential = $vcal->CloneConfidential();
328 $this->
resource->caldav_data = $confidential->Render();
330 if ( isset($c->hide_alarm) && $c->hide_alarm && !$this->HavePrivilegeTo(
'write') ) {
331 $vcal1 =
new iCalComponent($this->
resource->caldav_data);
332 $comps = $vcal1->GetComponents();
333 $vcal2 =
new iCalComponent();
335 foreach( $comps AS $comp ) {
336 $comp->ClearComponents(
'VALARM');
337 $vcal2->AddComponent($comp);
339 $this->
resource->displayname = $this->
resource->summary = $vcal2->GetPValue(
'SUMMARY');
340 $this->
resource->caldav_data = $vcal2->Render();
344 else if ( strtoupper(substr($this->
resource->caldav_data,0,11)) ==
'BEGIN:VCARD' ) {
345 $this->contenttype =
'text/vcard';
347 else if ( strtoupper(substr($this->
resource->caldav_data,0,11)) ==
'BEGIN:VLIST' ) {
348 $this->contenttype =
'text/x-vlist';
362 $this->
dav_name = DeconstructURL($inpath);
365 if ( $this->_is_collection ) {
366 if ( $this->_is_principal || $this->collection->type ==
'principal' ) $this->
FetchPrincipal();
371 dbg_error_log(
'DAVResource',
':FromPath: Path "%s" is%s a collection%s.',
372 $this->
dav_name, ($this->_is_collection?
' '.$this->resourcetypes:
' not'), ($this->_is_principal?
' and a principal':
'') );
376 private function ReadCollectionFromDatabase() {
379 $this->collection = (object) array(
380 'collection_id' => -1,
381 'type' =>
'nonexistent',
382 'is_calendar' =>
false,
'is_principal' =>
false,
'is_addressbook' =>
false 385 $base_sql =
'SELECT collection.*, path_privs(:session_principal::int8, collection.dav_name,:scan_depth::int), ';
386 $base_sql .=
'p.principal_id, p.type_id AS principal_type_id, ';
387 $base_sql .=
'p.displayname AS principal_displayname, p.default_privileges AS principal_default_privileges, ';
388 $base_sql .=
'timezones.vtimezone ';
389 $base_sql .=
'FROM collection LEFT JOIN principal p USING (user_no) ';
390 $base_sql .=
'LEFT JOIN timezones ON (collection.timezone=timezones.tzid) ';
391 $base_sql .=
'WHERE ';
392 $sql = $base_sql .
'collection.dav_name = :raw_path ';
393 $params = array(
':raw_path' => $this->
dav_name,
':session_principal' => $session->principal_id,
':scan_depth' => $c->permission_scan_depth );
394 if ( !preg_match(
'#/$#', $this->
dav_name ) ) {
395 $sql .=
' OR collection.dav_name = :up_to_slash OR collection.dav_name = :plus_slash ';
396 $params[
':up_to_slash'] = preg_replace(
'#[^/]*$#',
'', $this->
dav_name);
397 $params[
':plus_slash'] = $this->
dav_name.
'/';
399 $sql .=
'ORDER BY LENGTH(collection.dav_name) DESC LIMIT 1';
400 $qry =
new AwlQuery( $sql, $params );
401 if ( $qry->Exec(
'DAVResource') && $qry->rows() == 1 && ($row = $qry->Fetch()) ) {
402 $this->collection = $row;
403 $this->collection->exists =
true;
405 if ( $row->is_calendar ==
't' )
406 $this->collection->type =
'calendar';
407 else if ( $row->is_addressbook ==
't' )
408 $this->collection->type =
'addressbook';
409 else if ( preg_match(
'#^((/[^/]+/)\.(in|out)/)[^/]*$#', $this->
dav_name, $matches ) )
410 $this->collection->type =
'schedule-'. $matches[3].
'box';
412 $this->collection->type =
'collection';
414 # Vanilla collection, safe to cache.
415 $this->_collection_is_cacheable =
true;
417 else if ( preg_match(
'{^( ( / ([^/]+) / ) \.(in|out)/ ) [^/]*$}x', $this->
dav_name, $matches ) ) {
419 $params = array(
':username' => $matches[3],
':parent_container' => $matches[2],
':dav_name' => $matches[1] );
420 $params[
':boxname'] = ($matches[4] ==
'in' ?
' Inbox' :
' Outbox');
421 $this->collection_type =
'schedule-'. $matches[4].
'box';
422 $params[
':resourcetypes'] = sprintf(
'<DAV::collection/><urn:ietf:params:xml:ns:caldav:%s/>', $this->collection_type );
424 INSERT INTO collection (
user_no, parent_container,
dav_name, dav_displayname, is_calendar, created, modified, dav_etag, resourcetypes )
425 VALUES( (SELECT
user_no FROM usr WHERE username = text(:username)),
427 (SELECT fullname FROM usr WHERE username = text(:username)) || :boxname,
428 FALSE, current_timestamp, current_timestamp,
'1', :resourcetypes )
430 $qry =
new AwlQuery( $sql, $params );
431 $qry->Exec(
'DAVResource');
432 dbg_error_log(
'DAVResource',
'Created new collection as "%s".', trim($params[
':boxname']) );
434 $params = array(
':raw_path' => $this->
dav_name,
':session_principal' => $session->principal_id,
':scan_depth' => $c->permission_scan_depth );
435 $qry =
new AwlQuery( $base_sql .
' dav_name = :raw_path', $params );
436 if ( $qry->Exec(
'DAVResource') && $qry->rows() == 1 && ($row = $qry->Fetch()) ) {
437 $this->collection = $row;
438 $this->collection->exists =
true;
439 $this->collection->type = $this->collection_type;
441 # Vanilla collection, safe to cache. 442 $this->_collection_is_cacheable =
true;
445 else if ( preg_match(
'#^(/([^/]+)/calendar-proxy-(read|write))/?[^/]*$#', $this->
dav_name, $matches ) ) {
446 $this->collection->type =
'proxy';
447 $this->_is_proxy_resource =
true;
448 $this->proxy_type = $matches[3];
449 $this->collection->proxy_type = $matches[3];
450 $this->collection->dav_name = $this->dav_name;
451 $this->collection->dav_displayname = sprintf(
'%s proxy %s', $matches[2], $matches[3] );
452 $this->collection->exists =
true;
453 $this->collection->parent_container =
'/' . $matches[2] .
'/';
455 # Proxy collection, fetch from cache can handle the _is_proxy_resource and proxy_type metadata. 456 $this->_collection_is_cacheable =
true;
458 else if ( preg_match(
'#^(/[^/]+)/?$#', $this->
dav_name, $matches)
459 || preg_match(
'#^((/principals/[^/]+/)[^/]+)/?$#', $this->
dav_name, $matches) ) {
460 $this->_is_principal =
true;
462 $this->collection->is_principal =
true;
463 $this->collection->type =
'principal';
465 # We don't cache principals as a collection. 466 $this->_collection_is_cacheable =
false;
468 else if ( $this->
dav_name ==
'/' ) {
469 $this->collection->dav_name =
'/';
470 $this->collection->type =
'root';
471 $this->collection->exists =
true;
472 $this->collection->displayname = $c->system_name;
473 $this->collection->default_privileges = (1 | 16 | 32);
474 $this->collection->parent_container =
'/';
476 # Vanilla collection, safe to cache. 477 $this->_collection_is_cacheable =
true;
481 SELECT collection.*, path_privs(:session_principal::int8, collection.dav_name,:scan_depth::int), p.principal_id,
482 p.type_id AS principal_type_id, p.displayname AS principal_displayname, p.default_privileges AS principal_default_privileges,
483 timezones.vtimezone, dav_binding.access_ticket_id, dav_binding.parent_container AS bind_parent_container,
484 dav_binding.dav_displayname, owner.dav_name AS bind_owner_url, dav_binding.dav_name AS bound_to,
485 dav_binding.external_url AS external_url, dav_binding.type AS external_type, dav_binding.bind_id AS bind_id
487 LEFT JOIN collection ON (collection.collection_id=bound_source_id)
488 LEFT JOIN principal p USING (
user_no)
489 LEFT JOIN dav_principal owner ON (dav_binding.dav_owner_id=owner.principal_id)
490 LEFT JOIN timezones ON (collection.timezone=timezones.tzid)
491 WHERE dav_binding.dav_name = :raw_path
493 $params = array(
':raw_path' => $this->
dav_name,
':session_principal' => $session->principal_id,
':scan_depth' => $c->permission_scan_depth );
494 if ( !preg_match(
'#/$#', $this->
dav_name ) ) {
495 $sql .=
' OR dav_binding.dav_name = :up_to_slash OR collection.dav_name = :plus_slash OR dav_binding.dav_name = :plus_slash ';
496 $params[
':up_to_slash'] = preg_replace(
'#[^/]*$#',
'', $this->
dav_name);
497 $params[
':plus_slash'] = $this->
dav_name.
'/';
499 $sql .=
' ORDER BY LENGTH(dav_binding.dav_name) DESC LIMIT 1';
500 $qry =
new AwlQuery( $sql, $params );
501 if ( $qry->Exec(
'DAVResource',__LINE__,__FILE__) && $qry->rows() == 1 && ($row = $qry->Fetch()) ) {
502 $this->collection = $row;
503 $this->collection->exists =
true;
504 $this->collection->parent_set = $row->parent_container;
505 $this->collection->parent_container = $row->bind_parent_container;
506 $this->collection->bound_from = $row->dav_name;
507 $this->collection->dav_name = $row->bound_to;
508 if ( $row->is_calendar ==
't' )
509 $this->collection->type =
'calendar';
510 else if ( $row->is_addressbook ==
't' )
511 $this->collection->type =
'addressbook';
512 else if ( preg_match(
'#^((/[^/]+/)\.(in|out)/)[^/]*$#', $this->
dav_name, $matches ) )
513 $this->collection->type =
'schedule-'. $matches[3].
'box';
515 $this->collection->type =
'collection';
516 if ( isset($row->external_url) && strlen($row->external_url) > 8 ) {
517 $this->_is_external =
true;
518 if ( $row->external_type ==
'calendar' )
519 $this->collection->type =
'calendar';
520 else if ( $row->external_type ==
'addressbook' )
521 $this->collection->type =
'addressbook';
523 $this->collection->type =
'collection';
525 $this->_is_binding =
true;
526 $this->
bound_from = str_replace( $row->bound_to, $row->dav_name, $this->dav_name);
527 if ( isset($row->access_ticket_id) ) {
528 if ( !isset($this->tickets) ) $this->tickets = array();
529 $this->tickets[] =
new DAVTicket($row->access_ticket_id);
533 # A lot of metadata is stored outside of the Collection, and the 534 # Collection is what we cache. Caching this type isn't safe as we 535 # can't restore all the metadata. 536 $this->_collection_is_cacheable =
false;
539 dbg_error_log(
'DAVResource',
'No collection for path "%s".', $this->
dav_name );
540 $this->collection->exists =
false;
541 $this->collection->dav_name = preg_replace(
'{/[^/]*$}',
'/', $this->
dav_name);
542 $this->_collection_is_cacheable =
false;
565 dbg_error_log(
'DAVResource',
':FetchCollection: Looking for collection for "%s".', $this->
dav_name );
568 $cache = getCacheInstance();
569 $cache_ns =
'collection-'.preg_replace(
'{/[^/]*$}',
'/', $this->
dav_name);
570 $cache_key =
'dav_resource'.$session->user_no;
571 $this->collection = $cache->get( $cache_ns, $cache_key );
572 if ( $this->collection ===
false ) {
573 $this->ReadCollectionFromDatabase();
574 if ( $this->collection->type !=
'principal' && $this->_collection_is_cacheable ) {
575 $cache_ns =
'collection-'.$this->collection->dav_name;
576 @dbg_error_log(
'Cache',
':FetchCollection: Setting cache ns "%s" key "%s". Type: %s', $cache_ns, $cache_key, $this->collection->type );
577 $cache->set( $cache_ns, $cache_key, $this->collection );
579 @dbg_error_log(
'DAVResource',
':FetchCollection: Found collection named "%s" of type "%s".', $this->collection->dav_name, $this->collection->type );
582 @dbg_error_log(
'Cache',
':FetchCollection: Got cache ns "%s" key "%s". Type: %s', $cache_ns, $cache_key, $this->collection->type );
583 if ( preg_match(
'#^(/[^/]+)/?$#', $this->
dav_name, $matches)
584 || preg_match(
'#^((/principals/[^/]+/)[^/]+)/?$#', $this->
dav_name, $matches) ) {
585 $this->_is_principal =
true;
587 $this->collection->is_principal =
true;
588 $this->collection->type =
'principal';
590 if ($this->collection->type ==
'proxy') {
591 $this->_is_proxy_resource =
true;
592 $this->proxy_type = $this->collection->proxy_type;
595 @dbg_error_log(
'DAVResource',
':FetchCollection: Read cached collection named "%s" of type "%s".', $this->collection->dav_name, $this->collection->type );
598 if ( isset($this->collection->bound_from) ) {
599 $this->_is_binding =
true;
600 $this->
bound_from = str_replace( $this->collection->bound_to, $this->collection->bound_from, $this->dav_name);
601 if ( isset($this->collection->access_ticket_id) ) {
602 if ( !isset($this->tickets) ) $this->tickets = array();
603 $this->tickets[] =
new DAVTicket($this->collection->access_ticket_id);
607 $this->_is_collection = ( $this->_is_principal || $this->collection->dav_name == $this->
dav_name || $this->collection->dav_name == $this->
dav_name.
'/' );
608 if ( $this->_is_collection ) {
609 $this->
dav_name = $this->collection->dav_name;
610 $this->
resource_id = $this->collection->collection_id;
611 $this->_is_calendar = ($this->collection->type ==
'calendar');
612 $this->_is_addressbook = ($this->collection->type ==
'addressbook');
613 $this->contenttype =
'httpd/unix-directory';
614 if ( !isset($this->exists) && isset($this->collection->exists) ) {
616 $this->exists = $this->collection->exists;
618 if ( $this->exists ) {
619 if ( isset($this->collection->dav_etag) ) $this->
unique_tag =
'"'.$this->collection->dav_etag.
'"';
620 if ( isset($this->collection->created) ) $this->created = $this->collection->created;
621 if ( isset($this->collection->modified) ) $this->modified = $this->collection->modified;
622 if ( isset($this->collection->dav_displayname) ) $this->collection->displayname = $this->collection->dav_displayname;
626 $this->
user_no = $this->parent->GetProperty(
'user_no');
628 if ( isset($this->collection->resourcetypes) )
629 $this->resourcetypes = $this->collection->resourcetypes;
631 $this->resourcetypes =
'<DAV::collection/>';
632 if ( $this->_is_principal ) $this->resourcetypes .=
'<DAV::principal/>';
633 if ( $this->_is_addressbook ) $this->resourcetypes .=
'<urn:ietf:params:xml:ns:carddav:addressbook/>';
634 if ( $this->_is_calendar ) $this->resourcetypes .=
'<urn:ietf:params:xml:ns:caldav:calendar/>';
644 if ( isset($this->principal) )
return;
646 if ( $this->_is_principal ) {
647 $this->exists = $this->principal->Exists();
648 $this->collection->dav_name = $this->
dav_name();
649 $this->collection->type =
'principal';
650 if ( $this->exists ) {
651 $this->collection = $this->principal->AsCollection();
652 $this->displayname = $this->principal->GetProperty(
'displayname');
653 $this->
user_no = $this->principal->user_no();
654 $this->
resource_id = $this->principal->principal_id();
655 $this->created = $this->principal->created;
656 $this->modified = $this->principal->modified;
657 $this->resourcetypes = $this->principal->resourcetypes;
667 if ( isset($this->exists) )
return;
668 if ( $this->_is_collection )
return;
671 SELECT calendar_item.*, addressbook_resource.*, caldav_data.*
672 FROM caldav_data LEFT OUTER JOIN calendar_item USING (
collection_id,dav_id)
673 LEFT OUTER JOIN addressbook_resource USING (dav_id)
674 WHERE caldav_data.dav_name = :
dav_name 676 $params = array(
':dav_name' => $this->
bound_from() );
678 $qry =
new AwlQuery( $sql, $params );
679 if ( $qry->Exec(
'DAVResource') && $qry->rows() > 0 ) {
680 $this->exists =
true;
681 $row = $qry->Fetch();
685 $this->exists =
false;
694 if ( isset($this->dead_properties) )
return;
696 $this->dead_properties = array();
697 if ( !$this->exists || !$this->_is_collection )
return;
699 $qry =
new AwlQuery(
'SELECT property_name, property_value FROM property WHERE dav_name= :dav_name', array(
':dav_name' => $this->
dav_name) );
700 if ( $qry->Exec(
'DAVResource') ) {
701 while ( $property = $qry->Fetch() ) {
702 $this->dead_properties[$property->property_name] = self::BuildDeadPropertyXML($property->property_name,$property->property_value);
714 if ( !preg_match(
'{^\s*<.*>\s*$}s', $raw_string) )
return $raw_string;
716 if ( preg_match(
'{^(.*):([^:]+)$}', $property_name, $matches) ) {
717 $xmlns = $matches[1];
718 $property_name = $matches[2];
720 $xml = sprintf(
'<%s%s>%s</%s>', $property_name, (isset($xmlns)?
' xmlns="'.$xmlns.
'"':
''), $raw_string, $property_name);
721 $xml_parser = xml_parser_create_ns(
'UTF-8');
723 xml_parser_set_option ( $xml_parser, XML_OPTION_SKIP_WHITE, 1 );
724 xml_parser_set_option ( $xml_parser, XML_OPTION_CASE_FOLDING, 0 );
725 $rc = xml_parse_into_struct( $xml_parser, $xml, $xml_tags );
726 if ( $rc ==
false ) {
727 $errno = xml_get_error_code($xml_parser);
728 dbg_error_log(
'ERROR',
'XML parsing error: %s (%d) at line %d, column %d',
729 xml_error_string($errno), $errno,
730 xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser) );
731 dbg_error_log(
'ERROR',
"Error occurred in:\n%s\n",$xml);
732 if ($errno >= 200 && $errno < 300 && count($xml_tags) >= 3) {
734 dbg_error_log(
'ERROR',
'XML namespace error but tags extracted, trying to continue');
739 xml_parser_free($xml_parser);
740 $xmltree = BuildXMLTree( $xml_tags );
741 return $xmltree->GetContent();
748 global $session, $request;
750 if ( $this->
dav_name ==
'/' || $this->
dav_name ==
'' || $this->_is_external ) {
751 $this->privileges = (1 | 16 | 32);
752 dbg_error_log(
'DAVResource',
':FetchPrivileges: Read permissions for user accessing /' );
756 if ( $session->AllowedTo(
'Admin') ) {
757 $this->privileges = privilege_to_bits(
'all');
758 dbg_error_log(
'DAVResource',
':FetchPrivileges: Full permissions for an administrator.' );
764 $this->privileges = $this->principal->Privileges();
765 dbg_error_log(
'DAVResource',
':FetchPrivileges: Privileges of "%s" for user accessing principal "%s"', $this->privileges, $this->principal->username() );
770 $this->privileges = 0;
771 if ( !isset($this->collection->path_privs) ) {
774 $this->collection->path_privs = $this->parent->Privileges();
775 $this->collection->user_no = $this->parent->GetProperty(
'user_no');
776 $this->collection->principal_id = $this->parent->GetProperty(
'principal_id');
779 $this->privileges = $this->collection->path_privs;
780 if ( is_string($this->privileges) ) $this->privileges = bindec( $this->privileges );
782 dbg_error_log(
'DAVResource',
':FetchPrivileges: Privileges of "%s" for user "%s" accessing "%s"',
783 decbin($this->privileges), $session->username, $this->dav_name() );
785 if ( isset($request->ticket) && $request->ticket->MatchesPath($this->
bound_from()) ) {
786 $this->privileges |= $request->ticket->privileges();
787 dbg_error_log(
'DAVResource',
':FetchPrivileges: Applying permissions for ticket "%s" now: %s', $request->ticket->id(), decbin($this->privileges) );
790 if ( isset($this->tickets) ) {
792 foreach( $this->tickets AS $k => $ticket ) {
793 if ( $ticket->MatchesResource($this->resource_id()) || $ticket->MatchesPath($this->bound_from()) ) {
794 $this->privileges |= $ticket->privileges();
795 dbg_error_log(
'DAVResource',
':FetchPrivileges: Applying permissions for ticket "%s" now: %s', $ticket->id(), decbin($this->privileges) );
806 if ( $this->
dav_name ==
'/' )
return null;
807 if ( !isset($this->parent) ) {
808 if ( $this->_is_collection ) {
809 dbg_error_log(
'DAVResource',
'Retrieving "%s" - parent of "%s" (dav_name: %s)', $this->
parent_path(), $this->collection->dav_name, $this->dav_name() );
813 dbg_error_log(
'DAVResource',
'Retrieving "%s" - parent of "%s" (dav_name: %s)', $this->
parent_path(), $this->collection->dav_name, $this->dav_name() );
814 $this->parent =
new DAVResource($this->collection->dav_name);
817 return $this->parent;
826 deprecated(
'DAVResource::FetchParentContainer');
836 return $this->privileges;
848 if ( !isset($any) ) $any = ($do_what !=
'all');
849 $test_bits = privilege_to_bits( $do_what );
850 dbg_error_log(
'DAVResource',
'Testing %s privileges of "%s" (%s) against allowed "%s" => "%s" (%s)', ($any?
'any':
'exactly'),
851 $do_what, decbin($test_bits), decbin($this->privileges), ($this->privileges & $test_bits), decbin($this->privileges & $test_bits) );
853 return ($this->privileges & $test_bits) > 0;
856 return ($this->privileges & $test_bits) == $test_bits;
875 $request->NeedPrivilege( $privilege, $this->
dav_name );
884 if ( $privilege_names == null ) {
886 $privilege_names = bits_to_privilege($this->privileges, ($this->_is_collection ? $this->collection->type : null ) );
888 return privileges_to_XML( $privilege_names, $xmldoc);
896 if ( isset($this->supported_methods) )
return $this->supported_methods;
898 $this->supported_methods = array(
912 switch ( $this->collection->type ) {
916 $this->supported_methods = array(
923 case 'schedule-outbox':
924 $this->supported_methods = array_merge(
925 $this->supported_methods,
927 'POST' =>
'',
'PROPPATCH' =>
'',
'MKTICKET' =>
'',
'DELTICKET' =>
'' 931 case 'schedule-inbox':
933 $this->supported_methods[
'GET'] =
'';
934 $this->supported_methods[
'PUT'] =
'';
935 $this->supported_methods[
'HEAD'] =
'';
936 $this->supported_methods[
'MKTICKET'] =
'';
937 $this->supported_methods[
'DELTICKET'] =
'';
938 $this->supported_methods[
'ACL'] =
'';
941 $this->supported_methods[
'MKTICKET'] =
'';
942 $this->supported_methods[
'DELTICKET'] =
'';
943 $this->supported_methods[
'BIND'] =
'';
944 $this->supported_methods[
'ACL'] =
'';
946 $this->supported_methods[
'GET'] =
'';
947 $this->supported_methods[
'HEAD'] =
'';
948 $this->supported_methods[
'MKCOL'] =
'';
949 $this->supported_methods[
'MKCALENDAR'] =
'';
950 $this->supported_methods[
'PROPPATCH'] =
'';
951 $this->supported_methods[
'BIND'] =
'';
952 $this->supported_methods[
'ACL'] =
'';
957 $this->supported_methods = array_merge(
958 $this->supported_methods,
960 'GET' =>
'',
'HEAD' =>
'',
'PUT' =>
'',
'MKTICKET' =>
'',
'DELTICKET' =>
'' 965 return $this->supported_methods;
975 foreach( $this->supported_methods AS $k => $v ) {
977 $methods[] =
new XMLElement(
'supported-method', null, array(
'name' => $k) );
987 if ( isset($this->supported_reports) )
return $this->supported_reports;
989 $this->supported_reports = array(
990 'DAV::principal-property-search' =>
'',
991 'DAV::principal-search-property-set' =>
'',
992 'DAV::expand-property' =>
'',
993 'DAV::principal-match' =>
'',
994 'DAV::sync-collection' =>
'' 999 if ( $this->collection->is_calendar ) {
1000 $this->supported_reports = array_merge(
1001 $this->supported_reports,
1003 'urn:ietf:params:xml:ns:caldav:calendar-query' =>
'',
1004 'urn:ietf:params:xml:ns:caldav:calendar-multiget' =>
'',
1005 'urn:ietf:params:xml:ns:caldav:free-busy-query' =>
'' 1009 if ( $this->collection->is_addressbook ) {
1010 $this->supported_reports = array_merge(
1011 $this->supported_reports,
1013 'urn:ietf:params:xml:ns:carddav:addressbook-query' =>
'',
1014 'urn:ietf:params:xml:ns:carddav:addressbook-multiget' =>
'' 1018 return $this->supported_reports;
1028 foreach( $this->supported_reports AS $k => $v ) {
1029 dbg_error_log(
'DAVResource',
':BuildSupportedReports: Adding supported report "%s" which is "%s".', $k, $v );
1030 $report =
new XMLElement(
'report');
1031 $reply->NSElement($report, $k );
1032 $reports[] =
new XMLElement(
'supported-report', $report );
1043 if ( isset($this->access_tickets) )
return;
1044 $this->access_tickets = array();
1047 'SELECT access_ticket.*, COALESCE( resource.dav_name, collection.dav_name) AS target_dav_name, 1048 (access_ticket.expires < current_timestamp) AS expired, 1049 dav_principal.dav_name AS principal_dav_name, 1050 EXTRACT( \'epoch\' FROM (access_ticket.expires - current_timestamp)) AS seconds, 1051 path_privs(access_ticket.dav_owner_id,collection.dav_name,:scan_depth) AS grantor_collection_privileges 1052 FROM access_ticket JOIN collection ON (target_collection_id = collection_id) 1053 JOIN dav_principal ON (dav_owner_id = principal_id) 1054 LEFT JOIN caldav_data resource ON (resource.dav_id = access_ticket.target_resource_id) 1055 WHERE target_collection_id = :collection_id ';
1056 $params = array(
':collection_id' => $this->collection->collection_id,
':scan_depth' => $c->permission_scan_depth);
1058 $sql .=
'AND target_resource_id IS NULL';
1062 $sql .=
'AND target_resource_id = :dav_id';
1063 $params[
':dav_id'] = $this->
resource->dav_id;
1065 if ( isset($this->exists) && !$this->exists )
return;
1067 $qry =
new AwlQuery( $sql, $params );
1068 if ( $qry->Exec(
'DAVResource',__LINE__,__FILE__) && $qry->rows() ) {
1069 while( $ticket = $qry->Fetch() ) {
1070 $this->access_tickets[] = $ticket;
1087 global $session, $request;
1089 if ( !isset($this->access_tickets) ) $this->
FetchTickets();
1092 foreach( $this->access_tickets AS $meh => $trow ) {
1093 if ( !$show_all && ( $trow->dav_owner_id == $session->principal_id || $request->ticket->id() == $trow->ticket_id ) )
continue;
1094 dbg_error_log(
'DAVResource',
':BuildTicketinfo: Adding access_ticket "%s" which is "%s".', $trow->ticket_id, $trow->privileges );
1095 $ticket =
new XMLElement( $reply->Tag(
'ticketinfo',
'http://www.xythos.com/namespaces/StorageServer',
'TKT' ) );
1096 $reply->NSElement($ticket,
'http://www.xythos.com/namespaces/StorageServer:id', $trow->ticket_id );
1097 $reply->NSElement($ticket,
'http://www.xythos.com/namespaces/StorageServer:owner', $reply->href( ConstructURL($trow->principal_dav_name)) );
1098 $reply->NSElement($ticket,
'http://www.xythos.com/namespaces/StorageServer:timeout', (isset($trow->seconds) ? sprintf(
'Seconds-%d', $trow->seconds) :
'infinity') );
1099 $reply->NSElement($ticket,
'http://www.xythos.com/namespaces/StorageServer:visits',
'infinity' );
1101 foreach( bits_to_privilege(bindec($trow->privileges) & bindec($trow->grantor_collection_privileges) ) AS $k => $v ) {
1102 $privs[] = $reply->NewXMLElement($v);
1104 $reply->NSElement($ticket,
'DAV::privilege', $privs );
1105 $tickets[] = $ticket;
1119 if ( !isset($this->_locks_found) ) {
1120 $this->_locks_found = array();
1124 $sql =
'SELECT * FROM locks WHERE :this_path::text ~ (\'^\'||dav_name||:match_end)::text';
1125 $qry =
new AwlQuery($sql, array(
':this_path' => $this->
dav_name,
':match_end' => ($depth == DEPTH_INFINITY ?
'' :
'$') ) );
1126 if ( $qry->Exec(
'DAVResource',__LINE__,__FILE__) ) {
1127 while( $lock_row = $qry->Fetch() ) {
1128 $this->_locks_found[$lock_row->opaquelocktoken] = $lock_row;
1132 $this->DoResponse(500,i18n(
"Database Error"));
1137 foreach( $this->_locks_found AS $lock_token => $lock_row ) {
1138 if ( $lock_row->depth == DEPTH_INFINITY || $lock_row->dav_name == $this->dav_name ) {
1151 return $this->_is_collection;
1159 return $this->_is_collection && $this->_is_principal;
1167 return $this->_is_collection && $this->_is_calendar;
1176 if ( $this->_is_proxy_resource ) {
1177 return ($type ==
'any' || $type == $this->proxy_type);
1188 if ( $this->_is_collection && preg_match(
'{schedule-(inbox|outbox)}', $this->collection->type, $matches ) ) {
1189 return ($type ==
'any' || $type == $matches[1]);
1200 if ( !$this->_is_collection && preg_match(
'{schedule-(inbox|outbox)}', $this->collection->type, $matches ) ) {
1201 return ($type ==
'any' || $type == $matches[1]);
1211 return $this->_is_collection && $this->_is_addressbook;
1219 return $this->_is_binding;
1227 return $this->_is_external;
1235 if ( ! isset($this->exists) ) {
1238 $this->exists = $this->principal->Exists();
1245 return $this->exists;
1253 if ( $this->collection->dav_name != $this->dav_name ) {
1254 return $this->collection->exists;
1257 return $parent->Exists();
1267 throw Exception(
"What! How can dav_name not be set?");
1269 return ConstructURL($this->
dav_name);
1278 if ( isset($this->
dav_name) )
return $this->dav_name;
1288 if ( isset($this->
bound_from) )
return $this->bound_from;
1301 return $this->dav_name;
1311 if ( !isset($this->collection->parent_container) ) {
1312 $this->collection->parent_container = preg_replace(
'{[^/]+/$}',
'', $this->
bound_from());
1314 return $this->collection->parent_container;
1316 return preg_replace(
'{[^/]+$}',
'', $this->
bound_from());
1326 return $this->principal->url();
1335 return $this->principal->user_no();
1344 return $this->collection->collection_id;
1353 return $this->collection->timezone;
1362 return $this->resource;
1370 if ( isset($this->
unique_tag) )
return $this->unique_tag;
1371 if ( $this->
IsPrincipal() && !isset($this->principal) ) {
1373 $this->
unique_tag = $this->principal->unique_tag();
1379 return $this->unique_tag;
1387 if ( isset($this->
resource_id) )
return $this->resource_id;
1393 return $this->resource_id;
1401 dbg_error_log(
'DAVResource',
'Request for a%scached sync-token', ($cachedOK ?
' ' :
'n un') );
1404 if ( !isset($this->
sync_token) || !$cachedOK ) {
1405 $sql =
'SELECT new_sync_token( 0, :collection_id) AS sync_token';
1406 $params = array(
':collection_id' => $this->
collection_id());
1407 $qry =
new AwlQuery($sql, $params );
1408 if ( !$qry->Exec() || !$row = $qry->Fetch() ) {
1409 if ( !$qry->QDo(
'SELECT new_sync_token( 0, :collection_id) AS sync_token', $params) )
throw new Exception(
'Problem with database query');
1410 $row = $qry->Fetch();
1412 $this->
sync_token =
'data:,'.$row->sync_token;
1414 dbg_error_log(
'DAVResource',
'Returning sync token of "%s"', $this->
sync_token );
1415 return $this->sync_token;
1422 return ( isset($this->collection->publicly_readable) && $this->collection->publicly_readable ==
't' );
1430 return ( isset($this->collection->publicly_events_only) && $this->collection->publicly_events_only ==
't' );
1439 if ( !$this->
IsCollection() )
return $this->collection->type;
1441 if ( ! isset($this->collection->parent_container) )
return null;
1443 if ( isset($this->parent_container_type) )
return $this->parent_container_type;
1445 if ( preg_match(
'#/[^/]+/#', $this->collection->parent_container) ) {
1446 $this->parent_container_type =
'principal';
1449 $qry =
new AwlQuery(
'SELECT * FROM collection WHERE dav_name = :parent_name',
1450 array(
':parent_name' => $this->collection->parent_container ) );
1451 if ( $qry->Exec(
'DAVResource') && $qry->rows() > 0 && $parent = $qry->Fetch() ) {
1452 if ( $parent->is_calendar ==
't' )
1453 $this->parent_container_type =
'calendar';
1454 else if ( $parent->is_addressbook ==
't' )
1455 $this->parent_container_type =
'addressbook';
1456 else if ( preg_match(
'#^((/[^/]+/)\.(in|out)/)[^/]*$#', $this->
dav_name, $matches ) )
1457 $this->parent_container_type =
'schedule-'. $matches[3].
'box';
1459 $this->parent_container_type =
'collection';
1462 $this->parent_container_type = null;
1464 return $this->parent_container_type;
1472 $privilege_names = bits_to_privilege($privs, ($this->_is_collection ? $this->collection->type :
'resource'));
1473 $privileges = array();
1474 foreach( $privilege_names AS $k ) {
1475 $privilege =
new XMLElement(
'privilege');
1476 if ( isset($xmldoc) )
1477 $xmldoc->NSElement($privilege,$k);
1479 $privilege->NewElement($k);
1480 $privileges[] = $privilege;
1482 $ace =
new XMLElement(
'ace', array(
1483 new XMLElement(
'principal', $principal),
1484 new XMLElement(
'grant', $privileges ) )
1494 $default_privs = $this->principal->default_privileges;
1495 if ( isset($this->collection->default_privileges) ) $default_privs = $this->collection->default_privileges;
1498 $acl[] = $this->
BuildACE($xmldoc, pow(2,25) - 1,
new XMLElement(
'property',
new XMLElement(
'owner')) );
1500 $qry =
new AwlQuery(
'SELECT dav_principal.dav_name, grants.* FROM grants JOIN dav_principal ON (to_principal=principal_id) WHERE by_collection = :collection_id OR by_principal = :principal_id ORDER BY by_collection',
1501 array(
':collection_id' => $this->collection->collection_id,
1502 ':principal_id' => $this->principal->principal_id() ) );
1503 if ( $qry->Exec(
'DAVResource') && $qry->rows() > 0 ) {
1504 $by_collection = null;
1505 while( $grant = $qry->Fetch() ) {
1506 if ( !isset($by_collection) ) $by_collection = isset($grant->by_collection);
1507 if ( $by_collection && !isset($grant->by_collection) )
break;
1508 $acl[] = $this->
BuildACE($xmldoc, $grant->privileges, $xmldoc->href(ConstructURL($grant->dav_name)) );
1512 $acl[] = $this->
BuildACE($xmldoc, $default_privs,
new XMLElement(
'authenticated') );
1527 case 'collection_id':
1531 case 'principal_id':
1533 return $this->principal->principal_id();
1536 case 'resourcetype':
1537 if ( isset($this->resourcetypes) ) {
1538 $this->resourcetypes = preg_replace(
'{^\s*<(.*)/>\s*$}',
'$1', $this->resourcetypes);
1539 $type_list = preg_split(
'{(/>\s*<|\n)}', $this->resourcetypes);
1540 foreach( $type_list AS $k => $resourcetype ) {
1541 if ( preg_match(
'{^([^:]+):([^:]+) \s+ xmlns:([^=]+)="([^"]+)" \s* $}x', $resourcetype, $matches ) ) {
1542 $type_list[$k] = $matches[4] .
':' .$matches[2];
1544 else if ( preg_match(
'{^([^:]+) \s+ xmlns="([^"]+)" \s* $}x', $resourcetype, $matches ) ) {
1545 $type_list[$k] = $matches[2] .
':' .$matches[1];
1558 dbg_error_log(
'DAVResource',
':GetProperty: dav-data: fetched resource does%s exist.', ($this->exists?
'':
' not') );
1559 return $this->
resource->caldav_data;
1564 return clone($this->principal);
1568 if ( isset($this->{$name}) ) {
1569 if ( ! is_object($this->{$name}) )
return $this->{$name};
1570 return clone($this->{$name});
1572 if ( $this->_is_principal ) {
1574 if ( isset($this->principal->{$name}) )
return $this->principal->{$name};
1575 if ( isset($this->collection->{$name}) )
return $this->collection->{$name};
1577 else if ( $this->_is_collection ) {
1578 if ( isset($this->collection->{$name}) )
return $this->collection->{$name};
1579 if ( isset($this->principal->{$name}) )
return $this->principal->{$name};
1585 if ( isset($this->principal->{$name}) )
return $this->principal->{$name};
1586 if ( isset($this->collection->{$name}) )
return $this->collection->{$name};
1588 if ( isset($this->{$name}) ) {
1589 if ( ! is_object($this->{$name}) )
return $this->{$name};
1590 return clone($this->{$name});
1604 $allprop = array_merge( (isset($this->dead_properties)?array_keys($this->dead_properties):array()),
1605 (isset($include_properties)?$include_properties:array()),
1607 'DAV::getcontenttype',
'DAV::resourcetype',
'DAV::getcontentlength',
'DAV::displayname',
'DAV::getlastmodified',
1608 'DAV::creationdate',
'DAV::getetag',
'DAV::getcontentlanguage',
'DAV::supportedlock',
'DAV::lockdiscovery',
1609 'DAV::owner',
'DAV::principal-URL',
'DAV::current-user-principal',
1610 'urn:ietf:params:xml:ns:carddav:max-resource-size',
'urn:ietf:params:xml:ns:carddav:supported-address-data',
1611 'urn:ietf:params:xml:ns:carddav:addressbook-description',
'urn:ietf:params:xml:ns:carddav:addressbook-home-set' 1622 global $c, $session, $request;
1626 if ( $reply === null ) $reply = $GLOBALS[
'reply'];
1629 case 'DAV::allprop':
1631 $discarded = array();
1632 foreach( $property_list AS $k => $v ) {
1638 $prop->NewElement(
'href', ConstructURL($this->
dav_name) );
1641 case 'DAV::resource-id':
1643 $reply->DAVElement( $prop,
'resource-id', $reply->href(ConstructURL(
'/.resources/'.$this->
resource_id) ) );
1648 case 'DAV::parent-set':
1650 SELECT b.parent_container FROM dav_binding b JOIN collection c ON (b.bound_source_id=c.collection_id)
1651 WHERE regexp_replace( b.dav_name,
'^.*/', c.dav_name ) = :
bound_from 1653 $qry =
new AwlQuery($sql, array(
':bound_from' => $this->
bound_from() ) );
1655 if ( $qry->Exec(
'DAVResource',__LINE__,__FILE__) && $qry->rows() > 0 ) {
1656 while( $row = $qry->Fetch() ) {
1657 $parents[$row->parent_container] =
true;
1660 $parents[preg_replace(
'{(?<=/)[^/]+/?$}',
'',$this->
bound_from())] =
true;
1661 $parents[preg_replace(
'{(?<=/)[^/]+/?$}',
'',$this->
dav_name())] =
true;
1663 $parent_set = $reply->DAVElement( $prop,
'parent-set' );
1664 foreach( $parents AS $parent => $v ) {
1665 if ( preg_match(
'{^(.*)?/([^/]+)/?$}', $parent, $matches ) ) {
1666 $reply->DAVElement($parent_set,
'parent', array(
1667 new XMLElement(
'href', ConstructURL($matches[1])),
1668 new XMLElement(
'segment', $matches[2])
1671 else if ( $parent ==
'/' ) {
1672 $reply->DAVElement($parent_set,
'parent', array(
1673 new XMLElement(
'href',
'/'),
1674 new XMLElement(
'segment', ( ConstructURL(
'/') ==
'/caldav.php/' ?
'caldav.php' :
''))
1680 case 'DAV::getcontenttype':
1681 if ( !isset($this->contenttype) && !$this->_is_collection && !isset($this->
resource) ) $this->
FetchResource();
1682 $prop->NewElement(
'getcontenttype', $this->contenttype );
1685 case 'DAV::resourcetype':
1686 $resourcetypes = $prop->NewElement(
'resourcetype' );
1687 if ( $this->_is_collection ) {
1689 if ( !is_array($type_list) )
return true;
1691 foreach( $type_list AS $k => $v ) {
1692 if ( $v ==
'' )
continue;
1693 $reply->NSElement( $resourcetypes, $v );
1695 if ( $this->_is_binding ) {
1696 $reply->NSElement( $resourcetypes,
'http://xmlns.davical.org/davical:webdav-binding' );
1701 case 'DAV::getlastmodified':
1703 $reply->NSElement($prop, $tag, ISODateToHTTPDate($this->
GetProperty(
'modified')) );
1706 case 'DAV::creationdate':
1708 $reply->NSElement($prop, $tag, DateToISODate($this->
GetProperty(
'created'),
true) );
1711 case 'DAV::getcontentlength':
1712 if ( $this->_is_collection )
return false;
1715 $reply->NSElement($prop, $tag, strlen($this->
resource->caldav_data) );
1719 case 'DAV::getcontentlanguage':
1720 $locale = (isset($c->current_locale) ? $c->current_locale :
'');
1721 if ( isset($this->locale) && $this->locale !=
'' ) $locale = $this->locale;
1722 $reply->NSElement($prop, $tag, $locale );
1725 case 'DAV::acl-restrictions':
1726 $reply->NSElement($prop, $tag, array(
new XMLElement(
'grant-only'),
new XMLElement(
'no-invert') ) );
1729 case 'DAV::inherited-acl-set':
1730 $inherited_acls = array();
1731 if ( ! $this->_is_collection ) {
1732 $inherited_acls[] = $reply->href(ConstructURL($this->collection->dav_name));
1734 $reply->NSElement($prop, $tag, $inherited_acls );
1740 $reply->DAVElement( $prop,
'owner', $reply->href( ConstructURL($this->collection->bound_from )) );
1743 $reply->DAVElement( $prop,
'owner', $reply->href( ConstructURL(DeconstructURL($this->
principal_url())) ) );
1747 case 'DAV::add-member':
1748 if ( ! $this->_is_collection )
return false;
1749 if ( $this->_is_principal )
return false;
1750 if ( isset($c->post_add_member) && $c->post_add_member === false )
return false;
1751 $reply->DAVElement( $prop,
'add-member', $reply->href(ConstructURL(DeconstructURL($this->
url())).
'?add_member') );
1756 case 'DAV::alternate-URI-set':
1757 $reply->NSElement($prop, $tag );
1760 case 'DAV::getetag':
1761 if ( $this->_is_collection )
return false;
1762 $reply->NSElement($prop, $tag, $this->
unique_tag() );
1765 case 'http://calendarserver.org/ns/:getctag':
1766 if ( ! $this->_is_collection )
return false;
1767 $reply->NSElement($prop, $tag, $this->
unique_tag() );
1770 case 'DAV::sync-token':
1771 if ( ! $this->_is_collection )
return false;
1773 if ( empty($sync_token) )
return false;
1774 $reply->NSElement($prop, $tag, $sync_token );
1777 case 'http://calendarserver.org/ns/:calendar-proxy-read-for':
1778 $proxy_type =
'read';
1779 case 'http://calendarserver.org/ns/:calendar-proxy-write-for':
1780 if ( isset($c->disable_caldav_proxy) && $c->disable_caldav_proxy )
return false;
1781 if ( !isset($proxy_type) ) $proxy_type =
'write';
1784 $reply->CalendarserverElement($prop,
'calendar-proxy-'.$proxy_type.
'-for', $reply->href( $this->principal->ProxyFor($proxy_type) ) );
1787 case 'http://calendarserver.org/ns/:group-member-set':
1788 case 'DAV::group-member-set':
1789 if ( $this->_is_proxy_resource ) {
1791 if ( $this->proxy_type ==
'read' ) {
1792 $reply->DAVElement( $prop,
'group-member-set', $reply->href( $this->principal->ReadProxyGroup() ) );
1794 $reply->DAVElement( $prop,
'group-member-set', $reply->href( $this->principal->WriteProxyGroup() ) );
1801 case 'http://calendarserver.org/ns/:group-membership':
1802 case 'DAV::group-membership':
1803 if ( $this->_is_proxy_resource ) {
1805 $reply->NSElement($prop, $tag );
1811 case 'DAV::current-user-privilege-set':
1812 if ( $this->
HavePrivilegeTo(
'DAV::read-current-user-privilege-set') ) {
1820 case 'urn:ietf:params:xml:ns:caldav:supported-calendar-data':
1822 $reply->NSElement($prop, $tag,
'text/calendar' );
1825 case 'urn:ietf:params:xml:ns:caldav:supported-calendar-component-set':
1826 if ( ! $this->_is_collection )
return false;
1829 if ( isset($this->dead_properties[$tag]) ) {
1830 $set_of_components = $this->dead_properties[$tag];
1831 foreach( $set_of_components AS $k => $v ) {
1832 if ( preg_match(
'{(VEVENT|VTODO|VJOURNAL|VTIMEZONE|VFREEBUSY|VPOLL|VAVAILABILITY)}', $v, $matches) ) {
1833 $set_of_components[$k] = $matches[1];
1836 unset( $set_of_components[$k] );
1840 else if ( isset($c->default_calendar_components) && is_array($c->default_calendar_components) ) {
1841 $set_of_components = $c->default_calendar_components;
1844 $set_of_components = array(
'VEVENT',
'VTODO',
'VJOURNAL' );
1848 $set_of_components = array(
'VEVENT',
'VTODO',
'VFREEBUSY' );
1850 $components = array();
1851 foreach( $set_of_components AS $v ) {
1852 $components[] = $reply->NewXMLElement(
'comp',
'', array(
'name' => $v),
'urn:ietf:params:xml:ns:caldav');
1854 $reply->CalDAVElement($prop,
'supported-calendar-component-set', $components );
1857 case 'DAV::supported-method-set':
1861 case 'DAV::supported-report-set':
1865 case 'DAV::supportedlock':
1866 $prop->NewElement(
'supportedlock',
1867 new XMLElement(
'lockentry',
1869 new XMLElement(
'lockscope',
new XMLElement(
'exclusive')),
1870 new XMLElement(
'locktype',
new XMLElement(
'write')),
1876 case 'DAV::supported-privilege-set':
1877 $prop->NewElement(
'supported-privilege-set', $request->BuildSupportedPrivileges($reply) );
1880 case 'DAV::principal-collection-set':
1881 $prop->NewElement(
'principal-collection-set', $reply->href( ConstructURL(
'/') ) );
1884 case 'DAV::current-user-principal':
1885 $prop->NewElement(
'current-user-principal', $reply->href( ConstructURL(DeconstructURL($session->principal->url())) ) );
1888 case 'SOME-DENIED-PROPERTY':
1889 $denied[] = $reply->Tag($tag);
1892 case 'urn:ietf:params:xml:ns:caldav:calendar-timezone':
1893 if ( ! $this->_is_collection )
return false;
1894 if ( !isset($this->collection->vtimezone) || $this->collection->vtimezone ==
'' )
return false;
1896 $cal =
new iCalComponent();
1898 $cal->AddComponent(
new iCalComponent($this->collection->vtimezone) );
1899 $reply->NSElement($prop, $tag, $cal->Render() );
1902 case 'urn:ietf:params:xml:ns:carddav:address-data':
1903 case 'urn:ietf:params:xml:ns:caldav:calendar-data':
1904 if ( $this->_is_collection )
return false;
1905 if ( !isset($c->sync_resource_data_ok) || $c->sync_resource_data_ok == false )
return false;
1907 $reply->NSElement($prop, $tag, $this->
resource->caldav_data );
1910 case 'urn:ietf:params:xml:ns:carddav:max-resource-size':
1911 if ( ! $this->_is_collection || !$this->_is_addressbook )
return false;
1912 $reply->NSElement($prop, $tag, $c->carddav_max_resource_size );
1915 case 'urn:ietf:params:xml:ns:carddav:supported-address-data':
1916 if ( ! $this->_is_collection || !$this->_is_addressbook )
return false;
1917 $address_data = $reply->NewXMLElement(
'address-data',
false,
1918 array(
'content-type' =>
'text/vcard',
'version' =>
'3.0'),
'urn:ietf:params:xml:ns:carddav');
1919 $reply->NSElement($prop, $tag, $address_data );
1924 $reply->NSElement($prop, $tag, $this->
GetACL( $reply ) );
1931 case 'http://www.xythos.com/namespaces/StorageServer:ticketdiscovery':
1932 case 'DAV::ticketdiscovery':
1933 $reply->NSElement($prop,
'http://www.xythos.com/namespaces/StorageServer:ticketdiscovery', $this->
BuildTicketinfo($reply) );
1937 $property_value = $this->
GetProperty(preg_replace(
'{^(DAV:|urn:ietf:params:xml:ns:ca(rd|l)dav):}',
'', $tag));
1938 if ( isset($property_value) ) {
1939 $reply->NSElement($prop, $tag, $property_value );
1943 if ( isset($this->dead_properties[$tag]) ) {
1944 $reply->NSElement($prop, $tag, $this->dead_properties[$tag] );
1967 dbg_error_log(
'DAVResource',
':GetPropStat: propstat for href "%s"', $this->
dav_name );
1969 $prop =
new XMLElement(
'prop', null, null,
'DAV:');
1971 $not_found = array();
1972 foreach( $properties AS $k => $tag ) {
1973 if ( is_object($tag) ) {
1974 dbg_error_log(
'DAVResource',
':GetPropStat: "$properties" should be an array of text. Assuming this object is an XMLElement!.' );
1975 $tag = $tag->GetNSTag();
1980 $found = $this->principal->PrincipalProperty( $tag, $prop, $reply, $denied );
1984 $not_found[] = $tag;
1987 if ( $props_only )
return $prop;
1989 $status =
new XMLElement(
'status',
'HTTP/1.1 200 OK', null,
'DAV:' );
1991 $elements = array(
new XMLElement(
'propstat', array($prop,$status), null,
'DAV:' ) );
1993 if ( count($denied) > 0 ) {
1994 $status =
new XMLElement(
'status',
'HTTP/1.1 403 Forbidden', null,
'DAV:' );
1995 $noprop =
new XMLElement(
'prop', null, null,
'DAV:');
1996 foreach( $denied AS $k => $v ) {
1997 $reply->NSElement($noprop, $v);
1999 $elements[] =
new XMLElement(
'propstat', array( $noprop, $status), null,
'DAV:' );
2002 if ( !$request->PreferMinimal() && count($not_found) > 0 ) {
2003 $status =
new XMLElement(
'status',
'HTTP/1.1 404 Not Found', null,
'DAV:' );
2004 $noprop =
new XMLElement(
'prop', null, null,
'DAV:');
2005 foreach( $not_found AS $k => $v ) {
2006 $reply->NSElement($noprop,$v);
2008 $elements[] =
new XMLElement(
'propstat', array( $noprop, $status), null,
'DAV:' );
2022 function RenderAsXML( $properties, &$reply, $bound_parent_path = null ) {
2023 dbg_error_log(
'DAVResource',
':RenderAsXML: Resource "%s" exists(%d)', $this->
dav_name, $this->
Exists() );
2025 if ( !$this->
Exists() )
return null;
2027 $elements = $this->
GetPropStat( $properties, $reply );
2028 if ( isset($bound_parent_path) ) {
2032 $dav_name = $this->dav_name;
2035 array_unshift( $elements, $reply->href(ConstructURL($dav_name)));
2037 $response =
new XMLElement(
'response', $elements, null,
'DAV:' );
IsProxyCollection( $type='any')
IsSchedulingCollection( $type='any')
__construct( $parameters=null, DAVResource $prefetched_collection=null)
sync_token( $cachedOK=true)
BuildSupportedReports(&$reply)
NeedPrivilege( $privilege, $any=null)
BuildACE(&$xmldoc, $privs, $principal)
RenderAsXML( $properties, &$reply, $bound_parent_path=null)
static BuildDeadPropertyXML($property_name, $raw_string)
set_bind_location( $new_dav_name)
BuildPrivileges( $privilege_names=null, &$xmldoc=null)
HavePrivilegeTo( $do_what, $any=null)
GetPropStat( $properties, &$reply, $props_only=false)
ResourceProperty( $tag, $prop, &$reply, &$denied)
IsInSchedulingCollection( $type='any')