Refactor handling of requested properties in REPORT requests for better flexibility.

This commit is contained in:
Andrew McMillan 2007-08-26 11:23:00 +12:00
parent f0abf110bf
commit daab2bc748
4 changed files with 60 additions and 42 deletions

View File

@ -59,58 +59,76 @@ function calendar_to_xml( $properties, $item ) {
dbg_error_log("REPORT","Building XML Response for item '%s'", $item->dav_name );
$url = $c->protocol_server_port_script . $item->dav_name;
$prop = new XMLElement("prop");
if ( isset($properties['GETCONTENTLENGTH']) ) {
$contentlength = strlen($item->caldav_data);
$prop->NewElement("getcontentlength", $contentlength );
}
if ( isset($properties['CALENDAR-DATA']) ) {
$caldav_data = $item->caldav_data;
$displayname = $item->summary;
if ( isset($properties['CALENDAR-DATA']) || isset($properties['DISPLAYNAME']) ) {
if ( !is_numeric(strpos($item->permissions,'A')) && $session->user_no != $item->user_no ){
// the user is not admin / owner of this calendarlooking at his calendar and can not admin the other cal
if ( $item->class == 'CONFIDENTIAL' ) {
// if the event is confidential we fake one that just says "Busy"
$displayname = translate("Busy");
$ical = new iCalendar( array( "icalendar" => $item->caldav_data) );
$ical->Put( 'SUMMARY', translate("Busy") );
$ical->Put( 'SUMMARY', $displayname );
$caldav_data = $ical->render(true, $item->caldav_type, $ical->DefaultPropertyList() );
$prop->NewElement("calendar-data","$caldav_data" , array("xmlns" => "urn:ietf:params:xml:ns:caldav") );
}
elseif ( $c->hide_alarm ) {
// Otherwise we hide the alarms (if configured to)
$ical = new iCalendar( array( "icalendar" => $item->caldav_data) );
$caldav_data = $ical->render(true, $item->caldav_type, $ical->DefaultPropertyList() );
$prop->NewElement("calendar-data","$caldav_data" , array("xmlns" => "urn:ietf:params:xml:ns:caldav") );
}
else {
// Just send the raw event
$prop->NewElement("calendar-data", $item->caldav_data, array("xmlns" => "urn:ietf:params:xml:ns:caldav") );
}
}
else
// Just send the raw event
$prop->NewElement("calendar-data", $item->caldav_data, array("xmlns" => "urn:ietf:params:xml:ns:caldav") );
}
if ( isset($properties['GETCONTENTTYPE']) ) {
$prop->NewElement("getcontenttype", "text/calendar" );
}
if ( isset($properties['RESOURCETYPE']) ) {
$prop->NewElement("resourcetype", new XMLElement("calendar", false, array("xmlns" => "urn:ietf:params:xml:ns:caldav")) );
}
if ( isset($properties['DISPLAYNAME']) ) {
$prop->NewElement("displayname");
}
if ( isset($properties['GETETAG']) ) {
$prop->NewElement("getetag", '"'.$item->dav_etag.'"' );
}
if ( isset($properties['CURRENT-USER-PRIVILEGE-SET']) ) {
$prop->NewElement("current-user-privilege-set", privileges($request->permissions) );
$url = $c->protocol_server_port_script . $item->dav_name;
$prop = new XMLElement("prop");
foreach( $properties AS $k => $v ) {
switch( $k ) {
case 'GETCONTENTLENGTH':
$contentlength = strlen($item->caldav_data);
$prop->NewElement("getcontentlength", $contentlength );
break;
case 'CALENDAR-DATA':
$prop->NewElement("calendar-data","$caldav_data" , array("xmlns" => "urn:ietf:params:xml:ns:caldav") );
break;
case 'GETCONTENTTYPE':
$prop->NewElement("getcontenttype", "text/calendar" );
break;
case 'RESOURCETYPE':
$prop->NewElement("resourcetype", new XMLElement("calendar", false, array("xmlns" => "urn:ietf:params:xml:ns:caldav")) );
break;
case 'DISPLAYNAME':
$prop->NewElement("displayname", $displayname );
break;
case 'GETETAG':
$prop->NewElement("getetag", '"'.$item->dav_etag.'"' );
break;
case 'CURRENT-USER-PRIVILEGE-SET':
$prop->NewElement("current-user-privilege-set", privileges($request->permissions) );
break;
case 'SOME-DENIED-PROPERTY': /** TODO: indicating the style for future expansion */
$denied[] = $v;
break;
default:
dbg_error_log( 'REPORT', "Request for unsupported property '%s' of calendar item.", $v );
$unsupported[] = $v;
}
}
$status = new XMLElement("status", "HTTP/1.1 200 OK" );
$propstat = new XMLElement( "propstat", array( $prop, $status) );
$href = new XMLElement("href", $url );
$elements = array($href,$propstat);
$response = new XMLElement( "response", array($href,$propstat));
if ( count($denied) > 0 ) {
$status = new XMLElement("status", "HTTP/1.1 403 Forbidden" );
$noprop = new XMLElement("prop");
foreach( $denied AS $k => $v ) {
$noprop->NewElement( strtolower($v) );
}
$elements[] = new XMLElement( "propstat", array( $noprop, $status) );
}
$response = new XMLElement( "response", $elements );
return $response;
}

View File

@ -1,6 +1,6 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
ETag: "33afbc22a1752a395d24e4248bacbc6c"
ETag: "8f48e613721a5ccb5e44c277f7a1a909"
Content-Length: 1630
Content-Type: text/xml; charset="utf-8"
@ -10,6 +10,7 @@ Content-Type: text/xml; charset="utf-8"
<href>http://myapms/calendar/caldav.php/user1/home/2178279a-aec2-471f-832d-1f6df6203f2f.ics</href>
<propstat>
<prop>
<getetag>"509b0f0d8a3363379f9f5727f5dd74a0"</getetag>
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
PRODID:-//Mozilla Calendar//NONSGML Sunbird//EN
VERSION:2.0
@ -25,7 +26,6 @@ DESCRIPTION:This task is incomplete and has not been cancelled (has no
END:VTODO
END:VCALENDAR
</calendar-data>
<getetag>"509b0f0d8a3363379f9f5727f5dd74a0"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
@ -34,6 +34,7 @@ END:VCALENDAR
<href>http://myapms/calendar/caldav.php/user1/home/917b9e47-b748-4550-a566-657fbe672447.ics</href>
<propstat>
<prop>
<getetag>"cb3d9dc3e8c157f53eba3ea0e1e0f146"</getetag>
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
PRODID:-//Mozilla Calendar//NONSGML Sunbird//EN
VERSION:2.0
@ -51,7 +52,6 @@ DESCRIPTION:This task is in progress (50% complete) and has not been
END:VTODO
END:VCALENDAR
</calendar-data>
<getetag>"cb3d9dc3e8c157f53eba3ea0e1e0f146"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>

View File

@ -1,6 +1,6 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
ETag: "06d6c0c2aaf949e8b6d470d4e04521d4"
ETag: "3140e532d35ae4918005eb9bf5fcc26b"
Content-Length: 1456
Content-Type: text/xml; charset="utf-8"
@ -10,6 +10,7 @@ Content-Type: text/xml; charset="utf-8"
<href>http://mycaldav/caldav.php/user1/home/20061101T073004Z.ics</href>
<propstat>
<prop>
<getetag>"c3658901fd4689d4a1e1d6f08601ef4f"</getetag>
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Ximian//NONSGML Evolution Calendar//EN
@ -51,7 +52,6 @@ END:DAYLIGHT
END:VTIMEZONE
END:VCALENDAR
</calendar-data>
<getetag>"c3658901fd4689d4a1e1d6f08601ef4f"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>

View File

@ -1,6 +1,6 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
ETag: "633dcc2b9b64b628d737e4bb25104d16"
ETag: "8bb1ae7c599f81130860154adb77364b"
Content-Length: 5175
Content-Type: text/xml; charset="utf-8"
@ -10,6 +10,7 @@ Content-Type: text/xml; charset="utf-8"
<href>http://mycaldav/caldav.php/user1/home/3F4CF6227300FD062D9EF3CDFB30D32D-0.ics</href>
<propstat>
<prop>
<getetag>"2c32a2f8aba853654eb17fe037a4db4d"</getetag>
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//mulberrymail.com//Mulberry v4.0//EN
@ -44,7 +45,6 @@ UID:5A55230C8866CA8D3D325F3A@CA1CBED546AAE36FF3BC722E
END:VEVENT
END:VCALENDAR
</calendar-data>
<getetag>"2c32a2f8aba853654eb17fe037a4db4d"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
@ -53,6 +53,7 @@ END:VCALENDAR
<href>http://mycaldav/caldav.php/user1/home/20061101T073004Z.ics</href>
<propstat>
<prop>
<getetag>"c3658901fd4689d4a1e1d6f08601ef4f"</getetag>
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Ximian//NONSGML Evolution Calendar//EN
@ -94,7 +95,6 @@ END:DAYLIGHT
END:VTIMEZONE
END:VCALENDAR
</calendar-data>
<getetag>"c3658901fd4689d4a1e1d6f08601ef4f"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
@ -103,6 +103,7 @@ END:VCALENDAR
<href>http://mycaldav/caldav.php/user1/home/4aaf8f37-f232-4c8e-a72e-e171d4c4fe54.ics</href>
<propstat>
<prop>
<getetag>"a1c6404d61190f9574e2bfd69383f144"</getetag>
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
PRODID:-//Mozilla Calendar//NONSGML Sunbird//EN
VERSION:2.0
@ -140,7 +141,6 @@ END:DAYLIGHT
END:VTIMEZONE
END:VCALENDAR
</calendar-data>
<getetag>"a1c6404d61190f9574e2bfd69383f144"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
@ -149,6 +149,7 @@ END:VCALENDAR
<href>http://mycaldav/caldav.php/user1/home/1906b3ca-4890-468a-9b58-1de74bf2c716.ics</href>
<propstat>
<prop>
<getetag>"5def8ae2b20893a1c7f4dbaeb008f2f1"</getetag>
<calendar-data xmlns="urn:ietf:params:xml:ns:caldav">BEGIN:VCALENDAR
PRODID:-//Mozilla Calendar//NONSGML Sunbird//EN
VERSION:2.0
@ -187,7 +188,6 @@ END:DAYLIGHT
END:VTIMEZONE
END:VCALENDAR
</calendar-data>
<getetag>"5def8ae2b20893a1c7f4dbaeb008f2f1"</getetag>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>