* MUST return a 412 (Precondition Failed) response. */ $request->PreconditionFailed(412, 'if-match'); } if ($dav_resource->Exists()) { if (isset($request->etag_if_match) && $request->etag_if_match != '' && $request->etag_if_match != $dav_resource->unique_tag()) { /** * RFC2068, 14.25: * If none of the entity tags match, or if "*" is given and no current * entity exists, the server MUST NOT perform the requested method, and * MUST return a 412 (Precondition Failed) response. */ $request->PreconditionFailed(412, 'if-match', sprintf('Existing resource ETag of "%s" does not match "%s"', $dav_resource->unique_tag(), $request->etag_if_match)); } else { if (isset($request->etag_none_match) && $request->etag_none_match != '' && ($request->etag_none_match == $dav_resource->unique_tag() || $request->etag_none_match == '*')) { /** * RFC2068, 14.26: * If any of the entity tags match the entity tag of the entity that * would have been returned in the response to a similar GET request * (without the If-None-Match header) on that resource, or if "*" is * given and any current entity exists for that resource, then the * server MUST NOT perform the requested method. */ $request->PreconditionFailed(412, 'if-none-match', translate('Existing resource matches "If-None-Match" header - not accepted.')); } } } $put_action_type = $dav_resource->Exists() ? 'UPDATE' : 'INSERT'; write_resource($dav_resource->GetProperty('user_no'), $dav_resource->bound_from(), $request->raw_post, $dav_resource->GetProperty('collection_id'), $session->user_no, $etag, $ic, $put_action_type, true, true); header(sprintf('ETag: "%s"', $etag)); $request->DoResponse($dav_resource->Exists() ? 204 : 201);
if ($fh) { fwrite($fh, $request->raw_post); fclose($fh); } } controlRequestContainer($dav_resource->GetProperty('username'), $dav_resource->GetProperty('user_no'), $dav_resource->bound_from(), true); $lock_opener = $request->FailIfLocked(); if ($dav_resource->IsCollection()) { if ($dav_resource->IsPrincipal() || $dav_resource->IsBinding() || !isset($c->readonly_webdav_collections) || $c->readonly_webdav_collections == true) { $request->DoResponse(405); // Method not allowed return; } $appending = isset($_GET['mode']) && $_GET['mode'] == 'append'; /** * CalDAV does not define the result of a PUT on a collection. We treat that * as an import. The code is in caldav-PUT-functions.php */ import_collection($request->raw_post, $request->user_no, $request->path, true, $appending); $request->DoResponse(200); return; } $etag = md5($request->raw_post); $request->CheckEtagMatch($dav_resource->Exists(), $dav_resource->unique_tag()); $put_action_type = $dav_resource->Exists() ? 'UPDATE' : 'INSERT'; $collection = $dav_resource->GetParentContainer(); write_resource($dav_resource, $request->raw_post, $collection, $session->user_no, $etag, $put_action_type, true, true); if (isset($etag)) { header(sprintf('ETag: "%s"', $etag)); } $request->DoResponse($dav_resource->Exists() ? 204 : 201);
/** * A slightly simpler version of write_resource which will make more sense for calling from * an external program. This makes assumptions that the collection and user do exist * and bypasses all checks for whether it is reasonable to write this here. * @param string $path The path to the resource being written * @param string $caldav_data The actual resource to be written * @param string $put_action_type INSERT or UPDATE depending on what we are to do * @return boolean True for success, false for failure. */ function simple_write_resource($path, $caldav_data, $put_action_type, $write_action_log = false) { global $session; /** * We pull the user_no & collection_id out of the collection table, based on the resource path */ $dav_resource = new DAVResource($path); $etag = md5($caldav_data); $collection_path = preg_replace('#/[^/]*$#', '/', $path); $collection = new DAVResource($collection_path); if ($collection->IsCollection() || $collection->IsSchedulingCollection()) { return write_resource($dav_resource, $caldav_data, $collection, $session->user_no, $etag, $put_action_type, false, $write_action_log); } return false; }
/** * A slightly simpler version of write_resource which will make more sense for calling from * an external program. This makes assumptions that the collection and user do exist * and bypasses all checks for whether it is reasonable to write this here. * @param string $path The path to the resource being written * @param string $caldav_data The actual resource to be written * @param string $put_action_type INSERT or UPDATE depending on what we are to do * @return boolean True for success, false for failure. */ function simple_write_resource($path, $caldav_data, $put_action_type, $write_action_log = false) { $etag = md5($caldav_data); $ic = new iCalComponent($caldav_data); /** * We pull the user_no & collection_id out of the collection table, based on the resource path */ $collection_path = preg_replace('#/[^/]*$#', '/', $path); $qry = new AwlQuery('SELECT user_no, collection_id FROM collection WHERE dav_name = :dav_name ', array(':dav_name' => $collection_path)); if ($qry->Exec('PUT', __LINE__, __FILE__) && $qry->rows() == 1) { $collection = $qry->Fetch(); $user_no = $collection->user_no; return write_resource($user_no, $path, $caldav_data, $collection->collection_id, $user_no, $etag, $ic, $put_action_type, false, $write_action_log); } return false; }