Add support for arbitray text objects in collections.

This commit is contained in:
Andrew McMillan 2010-03-29 22:38:45 +13:00
parent e2f8ff8b0a
commit a2c3c4a620
3 changed files with 103 additions and 2 deletions

View File

@ -58,14 +58,27 @@ switch ( $request->method ) {
case 'OPTIONS': include_once('caldav-OPTIONS.php'); break;
case 'REPORT': include_once('caldav-REPORT.php'); break;
case 'PROPFIND': include('caldav-PROPFIND.php'); break;
case 'PUT': include('caldav-PUT.php'); break;
case 'GET': include('caldav-GET.php'); break;
case 'POST': include('caldav-POST.php'); break;
case 'HEAD': include('caldav-GET.php'); break;
case 'PROPPATCH': include('caldav-PROPPATCH.php'); break;
case 'PUT':
switch( $request->content_type ) {
case 'text/calendar':
/** use original DAViCal 'PUT' code which will be rewritten */
include('caldav-PUT.php');
break;
/* case 'text/vcard':
include('caldav-PUT-vcard.php');
break;*/
default:
include('caldav-PUT-default.php');
break;
}
break;
case 'MKCALENDAR': include('caldav-MKCOL.php'); break;
case 'MKCOL': include('caldav-MKCOL.php'); break;
case 'DELETE': include('caldav-DELETE.php'); break;
case 'POST': include('caldav-POST.php'); break;
case 'MOVE': include('caldav-MOVE.php'); break;
case 'ACL': include('caldav-ACL.php'); break;
case 'LOCK': include('caldav-LOCK.php'); break;

View File

@ -164,6 +164,9 @@ class CalDAVRequest
}
$this->method = $_SERVER['REQUEST_METHOD'];
$this->content_type = (isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : null);
if ( preg_match( '{^(\S+/\S+)\s*(;.*)?$}', $this->content_type, $matches ) ) {
$this->content_type = $matches[1];
}
$this->user_agent = ((isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "Probably Mulberry"));
/**

View File

@ -0,0 +1,85 @@
<?php
/**
* CalDAV Server - handle PUT method on unknown (arbitrary) content-types
*
* @package davical
* @subpackage caldav
* @author Andrew McMillan <andrew@morphoss.com>
* @copyright Morphoss Ltd
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
*/
dbg_error_log("PUT", "method handler");
require_once('DAVResource.php');
if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['put']) && $c->dbg['put'])) ) {
$fh = fopen('/tmp/PUT.txt','w');
if ( $fh ) {
fwrite($fh,$request->raw_post);
fclose($fh);
}
}
$lock_opener = $request->FailIfLocked();
$dest = new DAVResource($request->path);
$container = $dest->FetchParentContainer();
if ( ! $dest->Exists() ) {
if ( $container->IsPrincipal() ) {
$request->DoResponse(403,translate('A DAViCal principal collection may only contain collections'));
}
if ( ! $container->Exists() ) {
$request->DoResponse( 409, translate('Destination collection does not exist') );
}
$container->NeedPrivilege('DAV::bind');
}
else {
if ( $dest->IsCollection() ) {
if ( ! isset($c->readonly_webdav_collections) || $c->readonly_webdav_collections ) {
$request->DoResponse(403,translate('You may not PUT to a collection URL'));
}
$request->DoResponse(403,translate('PUT on a collection is only allowed for text/calendar content against a calendar collection'));
}
$dest->NeedPrivilege('DAV::write-content');
}
if ( isset($request->etag_none_match) && $request->etag_none_match != '*' && $dest->Exists() ) {
$request->DoResponse(412);
}
if ( isset($request->etag_if_match) && $request->etag_if_match != $dest->unique_tag() ) {
$request->DoResponse(412);
}
$collection_id = $container->GetProperty('collection_id');
$qry = new AwlQuery();
$qry->Begin();
$params = array(
':user_no' => $dest->GetProperty('user_no'),
':dav_name' => $dest->bound_from(),
':etag' => md5($request->raw_post),
':dav_data' => $request->raw_post,
':session_user' => $session->user_no
);
if ( $dest->Exists() ) {
$sql = 'UPDATE caldav_data SET caldav_data=:dav_data, dav_etag=:etag, logged_user=:session_user,
modified=current_timestamp WHERE user_no=:user_no AND dav_name=:dav_name';
$sync_change = 200;
}
else {
$sql = 'INSERT INTO caldav_data ( user_no, dav_name, dav_etag, caldav_data, logged_user, created, modified, collection_id )
VALUES( :user_no, :dav_name, :etag, :dav_data, :session_user, current_timestamp, current_timestamp, :collection_id )';
$params[':collection_id'] = $collection_id;
$sync_change = 201;
}
$qry->QDo( $sql, $params );
$qry->QDo("SELECT write_sync_change( $collection_id, $sync_change, :dav_name)", array(':dav_name' => $dest->bound_from() ) );
$qry = new AwlQuery('COMMIT');
if ( !$qry->Exec('move') ) rollback(500);
$request->DoResponse( 200 );