From 77f0d797fced8d37c59fbbb33fdfa24e48e125f3 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Tue, 3 Apr 2007 10:05:24 +1200 Subject: [PATCH] Add support for MKCALENDAR with XML. --- inc/caldav-MKCALENDAR.php | 80 +++++++++++++++++++ .../213-Moz-MKCALENDAR.result | 6 ++ .../regression-suite/213-Moz-MKCALENDAR.test | 23 ++++++ 3 files changed, 109 insertions(+) create mode 100644 testing/tests/regression-suite/213-Moz-MKCALENDAR.result create mode 100644 testing/tests/regression-suite/213-Moz-MKCALENDAR.test diff --git a/inc/caldav-MKCALENDAR.php b/inc/caldav-MKCALENDAR.php index 5ef3ba85..30c35270 100644 --- a/inc/caldav-MKCALENDAR.php +++ b/inc/caldav-MKCALENDAR.php @@ -20,6 +20,86 @@ if ( preg_match( '#^(.*/)([^/]+)(/)?$#', $request->path, $matches ) ) { $parent_container = $matches[1]; $displayname = $matches[2]; } + +if ( isset($request->xml_tags) ) { + /** + * The MKCALENDAR request may contain XML to set some DAV properties + */ + $position = 0; + $xmltree = BuildXMLTree( $request->xml_tags, $position); + // echo $xmltree->Render(); + if ( $xmltree->GetTag() != "URN:IETF:PARAMS:XML:NS:CALDAV:MKCALENDAR" ) { + $request->DoResponse( 403, "XML is not a URN:IETF:PARAMS:XML:NS:CALDAV:MKCALENDAR document" ); + } + $setprops = $xmltree->GetPath("/URN:IETF:PARAMS:XML:NS:CALDAV:MKCALENDAR/DAV::SET/DAV::PROP/*"); + + $propertysql = ""; + foreach( $setprops AS $k => $setting ) { + $tag = $setting->GetTag(); + $content = $setting->RenderContent(); + + switch( $tag ) { + + case 'DAV::DISPLAYNAME': + $displayname = $content; + $success[$tag] = 1; + break; + + case 'DAV::RESOURCETYPE': + /** + * Any value for resourcetype is ignored + */ + $success[$tag] = 1; + break; + + /** + * The following properties are read-only, so they will cause the request to fail + */ + case 'DAV::GETETAG': + case 'DAV::GETCONTENTLENGTH': + case 'DAV::GETCONTENTTYPE': + case 'DAV::GETLASTMODIFIED': + case 'DAV::CREATIONDATE': + case 'DAV::LOCKDISCOVERY': + case 'DAV::SUPPORTEDLOCK': + $failure['set-'.$tag] = new XMLElement( 'propstat', array( + new XMLElement( 'prop', new XMLElement($tag)), + new XMLElement( 'status', 'HTTP/1.1 409 Conflict' ), + new XMLElement('responsedescription', translate("Property is read-only") ) + )); + break; + + /** + * If we don't have any special processing for the property, we just store it verbatim (which will be an XML fragment). + */ + default: + $propertysql .= awl_replace_sql_args( "SELECT set_dav_property( ?, ?, ?, ? );", $request->path, $request->user_no, $tag, $content ); + $success[$tag] = 1; + break; + } + } + + /** + * If we have encountered any instances of failure, the whole damn thing fails. + */ + if ( count($failure) > 0 ) { + foreach( $success AS $tag => $v ) { + // Unfortunately although these succeeded, we failed overall, so they didn't happen... + $failure[] = new XMLElement( 'propstat', array( + new XMLElement( 'prop', new XMLElement($tag)), + new XMLElement( 'status', 'HTTP/1.1 424 Failed Dependency' ), + )); + } + + array_unshift( $failure, new XMLElement('href', $c->protocol_server_port_script . $request->path ) ); + $failure[] = new XMLElement('responsedescription', translate("Some properties were not able to be set.") ); + + $multistatus = new XMLElement( "multistatus", new XMLElement( 'response', $failure ), array('xmlns'=>'DAV:') ); + $request->DoResponse( 207, $multistatus->Render(0,''), 'text/xml; charset="utf-8"' ); + + } +} + $sql = "SELECT * FROM collection WHERE user_no = ? AND dav_name = ?;"; $qry = new PgQuery( $sql, $request->user_no, $request->path ); if ( ! $qry->Exec("MKCALENDAR") ) { diff --git a/testing/tests/regression-suite/213-Moz-MKCALENDAR.result b/testing/tests/regression-suite/213-Moz-MKCALENDAR.result new file mode 100644 index 00000000..2c6bd086 --- /dev/null +++ b/testing/tests/regression-suite/213-Moz-MKCALENDAR.result @@ -0,0 +1,6 @@ +HTTP/1.1 201 Created +Date: Dow, 01 Jan 2000 00:00:00 GMT +Cache-Control: no-cache +Content-Length: 0 +Content-Type: text/plain; charset=UTF-8 + diff --git a/testing/tests/regression-suite/213-Moz-MKCALENDAR.test b/testing/tests/regression-suite/213-Moz-MKCALENDAR.test new file mode 100644 index 00000000..e4b765a2 --- /dev/null +++ b/testing/tests/regression-suite/213-Moz-MKCALENDAR.test @@ -0,0 +1,23 @@ +# +# Make a calendar, with XML attached, for someone who we are allowed to write to +TYPE=MKCALENDAR +URL=http://mycaldav/caldav.php/resource1/home/ +HEAD + +HEADER=User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20061013 Thunderbird/1.5.0.7 +HEADER=Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 +HEADER=Accept-Language: en-us,en;q=0.5 +HEADER=Accept-Encoding: gzip,deflate +HEADER=Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 +HEADER=Content-Type: text/xml + +BEGINDATA + + + + + A Pretty Name + + + +ENDDATA