diff --git a/inc/caldav-PUT-default.php b/inc/caldav-PUT-default.php index 0e530873..1b670359 100644 --- a/inc/caldav-PUT-default.php +++ b/inc/caldav-PUT-default.php @@ -22,7 +22,18 @@ if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['put' $lock_opener = $request->FailIfLocked(); -$dest = new DAVResource($request->path); +if ( $add_member ) { + $request->path = $request->dav_name() . uuid(); + $dest = new DAVResource($request->path); + if ( $dest->Exists() ) { + $request->path = $request->dav_name() . uuid(); + $dest = new DAVResource($request->path); + if ( $dest->Exists() ) throw new Exception("Failed to generate unique segment name for add-member!"); + } +} +else { + $dest = new DAVResource($request->path); +} $container = $dest->GetParentContainer(); if ( $container->IsCalendar() ) { diff --git a/inc/caldav-PUT-vcalendar.php b/inc/caldav-PUT-vcalendar.php index 6f67a87c..a9f5cd8d 100644 --- a/inc/caldav-PUT-vcalendar.php +++ b/inc/caldav-PUT-vcalendar.php @@ -12,7 +12,30 @@ dbg_error_log("PUT", "method handler"); require_once('DAVResource.php'); -$dav_resource = new DAVResource($request->path); +include_once('caldav-PUT-functions.php'); + +$vcalendar = new vCalendar( $request->raw_post ); +$uid = $vcalendar->GetUID(); +if ( empty($uid) ) { + $uid = uuid(); + $vcalendar->SetUID($uid); +} + +if ( $add_member ) { + $request->path = $request->dav_name() . $uid . '.ics'; + $dav_resource = new DAVResource($request->path); + if ( $dav_resource->Exists() ) { + $uid = uuid(); + $vcalendar->SetUID($uid); + $request->path = $request->dav_name() . $uid . '.ics'; + $dav_resource = new DAVResource($request->path); + + if ( $dav_resource->Exists() ) throw new Exception("Failed to generate unique segment name for add-member!"); + } +} +else { + $dav_resource = new DAVResource($request->path); +} if ( ! $dav_resource->HavePrivilegeTo('DAV::write-content') ) { $request->DoResponse(403,'No write permission'); } @@ -29,7 +52,6 @@ if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['put' } } -include_once('caldav-PUT-functions.php'); controlRequestContainer( $dav_resource->GetProperty('username'), $dav_resource->GetProperty('user_no'), $dav_resource->bound_from(), true); $lock_opener = $request->FailIfLocked(); diff --git a/inc/caldav-PUT-vcard.php b/inc/caldav-PUT-vcard.php index 7988cbc1..cc83194d 100644 --- a/inc/caldav-PUT-vcard.php +++ b/inc/caldav-PUT-vcard.php @@ -22,7 +22,28 @@ if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['put' $lock_opener = $request->FailIfLocked(); -$dest = new DAVResource($request->path); +require_once('vcard.php'); +$vcard = new vCard( $request->raw_post ); +$uid = $vcard->GetPValue('UID'); +if ( empty($uid) ) { + $uid = uuid(); + $vcard->AddProperty('UID',$uid); +} + +if ( $add_member ) { + $request->path = $request->dav_name() . $uid . '.vcf'; + $dest = new DAVResource($request->path); + if ( $dest->Exists() ) { + $uid = uuid(); + $vcard->AddProperty('UID',$uid); + $request->path = $request->dav_name() . $uid . '.vcf'; + $dest = new DAVResource($request->path); + if ( $dest->Exists() ) throw new Exception("Failed to generate unique segment name for add-member!"); + } +} +else { + $dest = new DAVResource($request->path); +} $container = $dest->GetParentContainer(); if ( ! $dest->Exists() ) { @@ -56,8 +77,6 @@ $collection_id = $container->GetProperty('collection_id'); $original_etag = md5($request->raw_post); -require_once('vcard.php'); -$vcard = new vCard( $request->raw_post ); $qry = new AwlQuery(); $qry->Begin(); @@ -127,6 +146,8 @@ if ( !$qry->Commit() ) { $cache = getCacheInstance(); $cache->delete( 'collection-'.$container->dav_name(), null ); +if ( $add_member ) header('Location: '.$c->protocol_server_port_script.$request->path); + if ( $etag == $original_etag ) header('ETag: "'. $etag . '"' ); // Only send the ETag if we didn't change what they gave us. if ( $response_code == 200 ) $response_code = 204; $request->DoResponse( $response_code );