3 * CalDAV Server - handle PUT method
7 * @author Andrew McMillan <andrew@mcmillan.net.nz>
8 * @copyright Catalyst .Net Ltd, Morphoss Ltd
9 * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
11 dbg_error_log("PUT", "method handler");
13 require_once('DAVResource.php');
15 include_once('caldav-PUT-functions.php');
17 $vcalendar = new vCalendar( $request->raw_post
);
18 $uid = $vcalendar->GetUID();
21 $vcalendar->SetUID($uid);
25 $request->path
= $request->dav_name() . $uid . '.ics';
26 $dav_resource = new DAVResource($request->path
);
27 if ( $dav_resource->Exists() ) {
29 $vcalendar->SetUID($uid);
30 $request->path
= $request->dav_name() . $uid . '.ics';
31 $dav_resource = new DAVResource($request->path
);
33 if ( $dav_resource->Exists() ) throw new Exception("Failed to generate unique segment name for add-member!");
37 $dav_resource = new DAVResource($request->path
);
39 if ( ! $dav_resource->HavePrivilegeTo('DAV::write-content') ) {
40 $request->DoResponse(403,'No write permission');
43 if ( ! $dav_resource->Exists() && ! $dav_resource->HavePrivilegeTo('DAV::bind') ) {
44 $request->DoResponse(403,'No bind permission.');
47 if ( ! ini_get('open_basedir') && (isset($c->dbg
['ALL']) ||
(isset($c->dbg
['put']) && $c->dbg
['put'])) ) {
48 $fh = fopen('/tmp/PUT.txt','w');
50 fwrite($fh,$request->raw_post
);
55 controlRequestContainer( $dav_resource->GetProperty('username'), $dav_resource->GetProperty('user_no'), $dav_resource->bound_from(), true);
57 $lock_opener = $request->FailIfLocked();
60 if ( $dav_resource->IsCollection() ) {
61 if ( $dav_resource->IsPrincipal() ||
$dav_resource->IsBinding() ||
!isset($c->readonly_webdav_collections
) ||
$c->readonly_webdav_collections
== true ) {
62 $request->DoResponse( 405 ); // Method not allowed
66 $appending = (isset($_GET['mode']) && $_GET['mode'] == 'append' );
69 * CalDAV does not define the result of a PUT on a collection. We treat that
70 * as an import. The code is in caldav-PUT-functions.php
72 import_collection($request->raw_post
,$request->user_no
,$request->path
,true, $appending);
73 $request->DoResponse( 200 );
77 $etag = md5($request->raw_post
);
79 $request->CheckEtagMatch( $dav_resource->Exists(), $dav_resource->unique_tag() );
81 $put_action_type = ($dav_resource->Exists() ?
'UPDATE' : 'INSERT');
82 $collection = $dav_resource->GetParentContainer();
84 write_resource( $dav_resource, $request->raw_post
, $collection, $session->user_no
, $etag,
85 $put_action_type, true, true );
87 if ( isset($etag) ) header(sprintf('ETag: "%s"', $etag) );
89 $request->DoResponse( ($dav_resource->Exists() ?
204 : 201) );