From 6500f7313366a5a3ffb29f9e74222e0e2184c98a Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 5 Oct 2011 09:40:24 +0200 Subject: [PATCH 1/3] Add protocol://hostname onto location header per spec. --- htdocs/well-known.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/well-known.php b/htdocs/well-known.php index 2b71addf..64192d8e 100644 --- a/htdocs/well-known.php +++ b/htdocs/well-known.php @@ -17,7 +17,7 @@ if ( ! isset ( $request ) ) { switch ( $request->path ) { case '/.well-known/caldav': case '/.well-known/carddav': - header('Location: ' . ConstructURL('/',true) ); + header('Location: ' . $c->protocol_server_port . ConstructURL('/',true) ); $request->DoResponse(301); // Moved permanently // does not return. case '/.well-known/timezone': @@ -26,7 +26,7 @@ switch ( $request->path ) { $parameters .= ($parameters == '' ? '?' : '&' ); $parameters .= $k.'='.rawurlencode($v); } - header('Location: ' . str_replace('/caldav.php', '', ConstructURL('/tz.php',true)).$parameters ); + header('Location: ' . $c->protocol_server_port . str_replace('/caldav.php', '', ConstructURL('/tz.php',true)).$parameters ); $request->DoResponse(301); // Moved permanently // does not return. } From 850baa0dbfa7decf84f10236573eb1e86152a19e Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 5 Oct 2011 09:41:00 +0200 Subject: [PATCH 2/3] Support gzip/deflate/compress encoding of incoming entity for PUT etc. --- inc/CalDAVRequest.php | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/inc/CalDAVRequest.php b/inc/CalDAVRequest.php index 8b0dec7b..4ee230fd 100644 --- a/inc/CalDAVRequest.php +++ b/inc/CalDAVRequest.php @@ -115,7 +115,33 @@ class CalDAVRequest if ( !isset($this->options['allow_by_email']) ) $this->options['allow_by_email'] = false; if ( !isset($c->raw_post) ) $c->raw_post = file_get_contents( 'php://input'); - $this->raw_post = $c->raw_post; + if ( isset($_SERVER['HTTP_CONTENT_ENCODING']) ) { + @dbg_error_log('caldav', 'Content-Encoding: %s', $_SERVER['HTTP_CONTENT_ENCODING'] ); + switch( $_SERVER['HTTP_CONTENT_ENCODING'] ) { + case 'gzip': + $this->raw_post = gzdecode($c->raw_post); + break; + case 'deflate': + $this->raw_post = gzinflate($c->raw_post); + break; + case 'compress': + $this->raw_post = gzuncompress($c->raw_post); + break; + default: + if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || isset($c->dbg['caldav'])) ) { + $fh = fopen('/tmp/raw_post','w'); + if ( $fh ) { + fwrite($fh,$request->raw_post); + fclose($fh); + } + } + $this->PreconditionFailed(402, 'content-encoding', 'This server does not presently support content encoded with "%s"', $_SERVER['HTTP_CONTENT_ENCODING']); + } + $c->raw_post = $this->raw_post; + } + else { + $this->raw_post = $c->raw_post; + } if ( isset($debugging) && isset($_GET['method']) ) { $_SERVER['REQUEST_METHOD'] = $_GET['method']; @@ -139,11 +165,6 @@ class CalDAVRequest } $this->user_agent = ((isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "Probably Mulberry")); - if ( isset($_SERVER['HTTP_CONTENT_ENCODING']) ) { - @dbg_error_log('caldav', 'Content-Encoding: %s', $_SERVER['HTTP_CONTENT_ENCODING']); - $this->PreconditionFailed(402, 'content-encoding', 'This server does not presently support encoded content.'); - } - /** * A variety of requests may set the "Depth" header to control recursion */ @@ -1091,11 +1112,11 @@ EOSQL; * @param string $precondition The namespaced precondition tag. * @param string $explanation An optional text explanation for the failure. */ - function PreconditionFailed( $status, $precondition, $explanation = '') { + function PreconditionFailed( $status, $precondition, $explanation = '', $xmlns='DAV:') { $xmldoc = sprintf(' - + <%s/>%s -', str_replace('DAV::', '', $precondition), $explanation ); +', $xmlns, str_replace($xmlns.':', '', $precondition), $explanation ); $this->DoResponse( $status, $xmldoc, 'text/xml; charset="utf-8"' ); exit(0); // Unecessary, but might clarify things From 46f0bd289a893793c52322cc15849568af9593d5 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 5 Oct 2011 09:41:33 +0200 Subject: [PATCH 3/3] Errors in timezone protocol should be in timezone xmlns --- htdocs/tz.php | 2 +- inc/tz/expand.php | 2 +- inc/tz/get.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/tz.php b/htdocs/tz.php index b985b20f..8cbb4f28 100644 --- a/htdocs/tz.php +++ b/htdocs/tz.php @@ -26,7 +26,7 @@ $request = new CalDAVRequest(); $code_file = sprintf( 'tz/%s.php', $action ); if ( ! @include_once( $code_file ) ) { - $request->PreconditionFailed(400, "supported-action", 'The action "'.$action.'" is not understood.' ); + $request->PreconditionFailed(400, "supported-action", 'The action "'.$action.'" is not understood.', 'urn:ietf:params:xml:ns:timezone-service' ); } $request->DoResponse( 500, translate("The application failed to understand that request.") ); diff --git a/inc/tz/expand.php b/inc/tz/expand.php index 89a8c215..9a068132 100644 --- a/inc/tz/expand.php +++ b/inc/tz/expand.php @@ -14,7 +14,7 @@ require_once('RRule-v2.php'); if ( empty($format) ) $format = 'text/calendar'; if ( $format != 'text/calendar' ) { - $request->PreconditionFailed(403, 'supported-format', 'This server currently only supports text/calendar format.'); + $request->PreconditionFailed(403, 'supported-format', 'This server currently only supports text/calendar format.', 'urn:ietf:params:xml:ns:timezone-service' ); } if ( empty($start) ) $start = sprintf( '%04d-01-01', date('Y')); diff --git a/inc/tz/get.php b/inc/tz/get.php index 7f3c05aa..e7726f91 100644 --- a/inc/tz/get.php +++ b/inc/tz/get.php @@ -13,7 +13,7 @@ require_once('vCalendar.php'); if ( empty($format) ) $format = 'text/calendar'; if ( $format != 'text/calendar' ) { - $request->PreconditionFailed(403, 'supported-format', 'This server currently only supports text/calendar format.'); + $request->PreconditionFailed(403, 'supported-format', 'This server currently only supports text/calendar format.', 'urn:ietf:params:xml:ns:timezone-service'); } $sql = 'SELECT our_tzno, tzid, active, olson_name, vtimezone, etag, ';