From 424c6ada91e26125922b45e328e2349bf2ada9e9 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 11 Oct 2006 14:01:19 +1300 Subject: [PATCH] Code review and stylistic changes. Better error reporting. --- inc/caldav-GET.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/inc/caldav-GET.php b/inc/caldav-GET.php index c78412ce..521ebfc8 100644 --- a/inc/caldav-GET.php +++ b/inc/caldav-GET.php @@ -4,29 +4,43 @@ dbg_error_log("get", "GET method handler"); // The GET method is not sent with any wrapping XML so we simply fetch it -$get_path = $_SERVER['PATH_INFO']; - -$qry = new PgQuery( "SELECT * FROM caldav_data WHERE user_no = ? AND dav_name = ? ;", $session->user_no, $get_path); +$qry = new PgQuery( "SELECT * FROM caldav_data WHERE user_no = ? AND dav_name = ? ;", $session->user_no, $request_path); dbg_error_log("get", "%s", $qry->querystring ); if ( $qry->Exec("GET") && $qry->rows == 1 ) { $event = $qry->Fetch(); + /** + * FIXME: There may be some circumstances where someone wants to send + * an If-Match or If-None-Match header. I'm not sure what that means here, + * so we will leave it unimplemented at this point. + */ + header("HTTP/1.1 200 OK"); header("ETag: \"$event->dav_etag\""); - header("Content-Type: text/calendar"); + header("Content-type: text/calendar"); - print $event->caldav_data; + echo $event->caldav_data; dbg_error_log( "GET", "User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path); } -else if ( $qry->rows != 1 ) { +else if ( $qry->rows < 1 ) { + header("HTTP/1.1 404 Not Found"); + header("Content-type: text/plain"); + echo "Calendar Resource Not Found."; + dbg_error_log("ERROR", "No rows match for User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path); +} +else if ( $qry->rows > 1 ) { header("HTTP/1.1 500 Internal Server Error"); + header("Content-type: text/plain"); + echo "Database Error - Multiple Rows Match"; dbg_error_log("ERROR", "Multiple rows match for User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path); } else { header("HTTP/1.1 500 Infernal Server Error"); - dbg_error_log("get", "Infernal Server Error"); + header("Content-type: text/plain"); + echo "Database Error"; + dbg_error_log("get", "Database Error"); } ?> \ No newline at end of file