source: contrib/davical/inc/caldav-PUT.php @ 3733

Revision 3733, 3.7 KB checked in by gabriel.malheiros, 13 years ago (diff)

Ticket #1541 - <Davical customizado para o Expresso.Utiliza Caldav e CardDav?>

Line 
1<?php
2/**
3* CalDAV Server - handle PUT method
4*
5* @package   davical
6* @subpackage   caldav
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
10*/
11dbg_error_log("PUT", "method handler");
12
13require_once('DAVResource.php');
14
15$dav_resource = new DAVResource($request->path);
16if ( ! $dav_resource->HavePrivilegeTo('DAV::write-content') ) {
17  $request->DoResponse(403);
18}
19
20if ( ! $dav_resource->Exists() && ! $dav_resource->HavePrivilegeTo('DAV::bind') ) {
21  $request->DoResponse(403);
22}
23
24if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['put']) && $c->dbg['put'])) ) {
25  $fh = fopen('/tmp/PUT.txt','w');
26  if ( $fh ) {
27    fwrite($fh,$request->raw_post);
28    fclose($fh);
29  }
30}
31
32include_once('caldav-PUT-functions.php');
33
34//controlRequestContainer( $dav_resource->GetProperty('username'), $dav_resource->GetProperty('user_no'), $dav_resource->bound_from(), true);
35
36$lock_opener = $request->FailIfLocked();
37
38
39//if ( $dav_resource->IsCollection()  ) {
40//  if ( $dav_resource->IsPrincipal() || $dav_resource->IsBinding() || !isset($c->readonly_webdav_collections) || $c->readonly_webdav_collections == true ) {
41//    $request->DoResponse( 405 ); // Method not allowed
42//    return;
43//  }
44 
45//  $appending = (isset($_GET['mode']) && $_GET['mode'] == 'append' );
46
47  /**
48  * CalDAV does not define the result of a PUT on a collection.  We treat that
49  * as an import. The code is in caldav-PUT-functions.php
50  */
51//  import_collection($request->raw_post,$request->user_no,$request->path,true, $appending);
52//  $request->DoResponse( 200 );
53//  return;
54//}
55
56$etag = md5($request->raw_post);
57$ic = new iCalComponent( $request->raw_post );
58
59if ( ! $dav_resource->Exists() && (isset($request->etag_if_match) && $request->etag_if_match != '') ) {
60  /**
61  * RFC2068, 14.25:
62  * If none of the entity tags match, or if "*" is given and no current
63  * entity exists, the server MUST NOT perform the requested method, and
64  * MUST return a 412 (Precondition Failed) response.
65  */
66  $request->PreconditionFailed(412,'if-match');
67}
68
69if ( $dav_resource->Exists() ) {
70  //if ( isset($request->etag_if_match) && $request->etag_if_match != '' && $request->etag_if_match != $dav_resource->unique_tag() ) {
71    /**
72    * RFC2068, 14.25:
73    * If none of the entity tags match, or if "*" is given and no current
74    * entity exists, the server MUST NOT perform the requested method, and
75    * MUST return a 412 (Precondition Failed) response.
76    */
77    //$request->PreconditionFailed(412,'if-match', translate( 'Existing resource does not match "If-Match" header - not accepted.'));
78  //}
79   if ( isset($request->etag_none_match) && $request->etag_none_match != ''
80               && ($request->etag_none_match == $dav_resource->unique_tag() || $request->etag_none_match == '*') ) {
81    /**
82    * RFC2068, 14.26:
83    * If any of the entity tags match the entity tag of the entity that
84    * would have been returned in the response to a similar GET request
85    * (without the If-None-Match header) on that resource, or if "*" is
86    * given and any current entity exists for that resource, then the
87    * server MUST NOT perform the requested method.
88    */
89    $request->PreconditionFailed(412,'if-none-match', translate( 'Existing resource matches "If-None-Match" header - not accepted.'));
90  }
91}
92
93$put_action_type = ($dav_resource->Exists() ? 'UPDATE' : 'INSERT');
94
95
96write_resource( $dav_resource->GetProperty('user_no'), $dav_resource->bound_from(), $request->raw_post, $dav_resource->GetProperty('collection_id'),
97                                $session->user_no, $etag, $ic, $put_action_type, true, true );
98
99header(sprintf('ETag: "%s"', $etag) );
100
101$request->DoResponse( ($dav_resource->Exists() ? 204 : 201) );
Note: See TracBrowser for help on using the repository browser.