From 20a47c5fb2d7810ee4900114c5a6e40a4ec1c28f Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Mon, 8 Mar 2010 17:46:24 +1300 Subject: [PATCH] Rewrite OPTIONS response to use DAVResource. --- inc/caldav-OPTIONS.php | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/inc/caldav-OPTIONS.php b/inc/caldav-OPTIONS.php index 714d8d83..9589de64 100644 --- a/inc/caldav-OPTIONS.php +++ b/inc/caldav-OPTIONS.php @@ -10,40 +10,16 @@ */ dbg_error_log("OPTIONS", "method handler"); -$request->NeedPrivilege( 'DAV::read' ); +include_once('DAVResource.php'); +$resource = new DAVResource($request->path); -$exists = false; -$is_calendar = false; +$resource->NeedPrivilege( 'DAV::read' ); -if ( $request->path == '/' ) { - $exists = true; -} -else { - if ( preg_match( '#^/[^/]+/$#', $request->path) ) { - $sql = "SELECT user_no, '/' || username || '/' AS dav_name, md5( '/' || username || '/') AS dav_etag, "; - $sql .= "updated AS created, fullname AS dav_displayname, FALSE AS is_calendar FROM usr WHERE user_no = $request->user_no ; "; - } - else { - $sql = "SELECT user_no, dav_name, dav_etag, created, dav_displayname, is_calendar FROM collection WHERE user_no = $request->user_no AND dav_name = ".qpg($request->path); - } - $qry = new PgQuery($sql ); - if( $qry->Exec("OPTIONS",__LINE__,__FILE__) && $qry->rows > 0 && $collection = $qry->Fetch() ) { - $is_calendar = ($collection->is_calendar == 't'); - $exists = true; - } - elseif ( $c->collections_always_exist && preg_match( "#^/$session->username/#", $request->path) ) { - $exists = true; - // Possibly this should be another setting, but it seems unlikely that something that - // can't deal with collections would issue MKCALENDAR or PROPPATCH commands. - $is_calendar = true; - } -} - -if ( !$exists ) { +if ( !$resource->Exists() ) { $request->DoResponse( 404, translate("No collection found at that location.") ); } -$allowed = implode( ', ', array_keys($request->supported_methods) ); +$allowed = implode( ', ', array_keys($resource->FetchSupportedMethods()) ); header( 'Allow: '.$allowed); $request->DoResponse( 200, "" );